문제

I have following query in my code:

var query3 = (from b in context.SystemDetails.Include("UserHousing").Include("UserInfo") where (b.UserHousing.UserInfo.FullName.StartsWith("Far")) select b).ToList();

Why does it give error that systemDeail do not have navigation property "UserInfo" .. it should not matter as UserHousing Have that Navigation property...

도움이 되었습니까?

해결책

You should specify the correct path to UserInfo:

context.SystemDetails.Include("UserHousing.UserInfo")

Or

context.SystemDetails.Include(x => x.UserHousing.UserInfo)

다른 팁

Your sequence of Include(..) methods is executed against main object being retrieved from context - SystemDetails, and, of course, it doesn't have UserInfo in it.

Paths are all-inclusive. Having both includes replaced with single

Include("UserHousing.UserInfo")

will do the trick. Have a look at documentation for Include(string path) method.

PS. What version of EF are you using? While updating to EF5 I've found following IQueryable extension useful:

DbExtensions.Include<T, TProperty> Method (IQueryable<T>,Expression<Func<T, TProperty>>)

http://msdn.microsoft.com/en-us/library/gg671236%28v=vs.103%29.aspx

See the remarks sections, I believe you are dealing with the following scenario:

  • To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference).

you should end up with something like this in your query:

from b in context.SystemDetails
.Include(detail => detail.UserHousing.UserInfo) ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top