EF4 多对多导航属性为空
使用模型优先方法,我创建了 2 个实体:项目和用户。一个项目有多个用户(参与该项目),并且一个用户有(访问)多个项目,因此按照 Tekpub 视频,我使用两个实体的主键创建了多对多导航属性。
我做了一些测试数据,数据正常,但是在 ASP.NET MVC 中,当尝试创建项目列表(包含每个项目用户的子列表)时,用户列表为空(它们已初始化,但是,即不为空),反之亦然(用户列表、项目子列表为空)。
所以我想我的问题是,如何调试它如何获取这些导航属性以及为什么它们不返回任何内容?
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 is, how do I debug how it's fetching those navigation properties and why they're returning nothing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢另一篇文章,我需要在查询中使用关键字“Include”。因此,当尝试加载用户及其关联项目时,它是:
而不是简单地:
并且非 linq 将是 Repository.Users.Include("Projects");
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:
Rather than simply:
And non-linq would be Repository.Users.Include("Projects");