You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ArgumentException: The given expression '([o] As Bar)' does not contain the searched expression '[o]' #12741
classProgram{staticvoidMain(string[]args){using(varctx=newMyContext()){ctx.Database.EnsureDeleted();ctx.Database.EnsureCreated();varf=newFoo();ctx.Foos.AddRange(f);ctx.SaveChanges();}using(varctx=newMyContext()){varquery1=ctx.Foos.Select(b =>(Bar)b).ToList();// this worksvarquery2=ctx.Foos.Select(b =>basBar).ToList();// this fails}}}publicclassMyContext:DbContext{publicDbSet<Foo>Foos{get;set;}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){modelBuilder.Entity<Bar>();}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseSqlServer(@"Server=.;Database=Repro12741;Trusted_Connection=True;MultipleActiveResultSets=True");}}publicclassFoo:Bar{}publicclassBar{publicintId{get;set;}}
This is because relinq's AccessorFindingExpressionVisitor doesn't properly handle TypAs expression. Workaround is to use hard cast instead (shown in repro code above).
Activity
myrup commentedon Jul 20, 2018
Forgot to mention
context.Foos.ToList().Select(b => b as Bar).ToList();gives the desired result.maumar commentedon Aug 17, 2018
Full repro:
maumar commentedon Aug 17, 2018
This is because relinq's AccessorFindingExpressionVisitor doesn't properly handle TypAs expression. Workaround is to use hard cast instead (shown in repro code above).
Filed a bug on relinq to track this: https://www.re-motion.org/jira/browse/RMLNQ-124
2 remaining items
maumar commentedon Sep 11, 2019
verified this issue has been fixed in 3.0
Adding regression tests for issues that have been fixed already
Adding regression tests for issues that have been fixed already