开发者

EF4 many-to-many navigation property is empty

Using the model-first approach, I made 2 entities: Project and User. A project has multiple Users (involved in the project), and a User has (access to) multiple Projects, so following along with the Tekpub video, I made the many-to-many navigation property using the primary keys of the two entities.

I made some test data, and the data is a-ok, however in ASP.NET MVC, when attempting to create a list of projects, with sub-lists of each project's users, the user lists are empty(they're initialized, though, ie. not null), and vice-versa (list of users, project sub-lists are empty).

So I suppose my question 开发者_C百科is, how do I debug how it's fetching those navigation properties and why they're returning nothing?


Thanks to another post, I needed to use the keyword "Include" in my query. So when trying to load a user and his associated projects, it was:

from o in Repository.Users.Include("Projects")
select o;

Rather than simply:

from o in Repository.Users
select o;

And non-linq would be Repository.Users.Include("Projects");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜