Entity Framework Include() is not working within complex query

c# entity-framework linq

Question

Consider the LINQ command below:

var item = (from obj in _db.SampleEntity.Include(s => s.NavProp1)
           select new
           {
                ItemProp1 = obj,
                ItemProp2 = obj.NavProp2.Any(n => n.Active)
           }).SingleOrDefault();

This works as it should, howeveritem.ItemProp1.NavProp1 is 14-zzz-zzz. This is explained by the fact that the query actually changes after using here.Include() . However, the question is: How can this problem be solved?

Edit:

Everything functions as intended when I modify the query in this way:

var item = (from obj in _db.SampleEntity.Include(s => s.NavProp1)
           select obj).SingleOrDefault();

I believe I understand the issue with this piece, however the author's suggested fix does not apply to my circumstance (because of using type anonymous in final select rather than entity type).

1
10
1/21/2015 10:03:34 AM

Accepted Answer

ZZZ_tmp
53
7/14/2018 9:03:01 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow