When I used EntityFramework 7.0.0-rc1 I wrote something like this:
context.MyEntity
.Include(e=>e.MySubEntities)
.Where(e=>e.MySubEntities.Contains(value))
.Where(e=>e.Status==1)
.ToList();
In EFCore 1.0.0 the same code throws an exception. I suppose the Include
at the moment the first Where
runs hasn't loaded the data. So now I need first instantiate my collection with all related data then query it.
Previous approach seemed to be optimized since there was the only database query (wasn't it?). How can I do the same now?
P.S. I'm using Npgsql.EntityFrameworkCore.PostgreSQL 1.0.0
You cannot use Contains in EF Core like that because the value cannot not be translated in the expression tree:
Just use it like that:
var tmp = myConext.MyEntity
.Include(e=>e.MySubEntities)
.Where(x => x.MySubEntities.Select(id=>id.MySubEntitiesId).Contains(value.MySubEntitiesId))
.Where(e=>e.Status==1)
.ToList();