Linq-To-Entity 包括
我目前正在学习更多有关 Linq-To-Entities 的知识 - 特别是目前有关急切加载和延迟加载的知识。
proxy.User.Include("Role").First(u => u.UserId == userId)
这应该加载用户以及用户拥有的任何角色。我有一个问题,但我也有一个问题。这只是一个为了解 L2E 而创建的简单模型,
我的印象是,这是为了使事物强类型化而设计的 - 那么为什么我必须写“角色”呢?看来,如果我更改表的名称,那么这不会产生编译错误...
我的错误是这样的:
The specified type member 'Roles' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
下面的解决方案允许我现在编写代码:
proxy.User.Include(u => u.Role).First(u => u.UserId == userId)
这更好!
I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about eager and lazy loading.
proxy.User.Include("Role").First(u => u.UserId == userId)
This is supposed to load the User, along with any roles that user has. I have a problem, but I also have a question. It's just a simple model created to learn about L2E
I was under the impression that this was designed to make things strongly type - so why do I have to write "Role"? It seems that if I changed the name of the table, then this wouldn't create a compilation error...
My error is this:
The specified type member 'Roles' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
The solution below allows me to now write the code:
proxy.User.Include(u => u.Role).First(u => u.UserId == userId)
Which is MUCH nicer!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)