.net实体模型框架中多对多关系的问题
这是我的代码:
var q = (from m in context.aspnet_Users
where m.UserName.Equals(username)
select new { m, m.aspnet_Roles.SourceRoleName }).FirstOrDefault();
但它给了我错误:
指定类型成员 不支持“SourceRoleName” LINQ 到实体。仅初始化器, 实体成员和实体导航 支持属性。
我如何使用接口表解决这个多对多关系,但.net框架删除接口表并生成与映射到它的表的关联,这是多对多的。
我需要角色名称,如何在这种模型中获得它?
here is my code :
var q = (from m in context.aspnet_Users
where m.UserName.Equals(username)
select new { m, m.aspnet_Roles.SourceRoleName }).FirstOrDefault();
but it gets me error :
The specified type member
'SourceRoleName' is not supported in
LINQ to Entities. Only initializers,
entity members, and entity navigation
properties are supported.
How I can solve this it many-to-many relationship using a interface table but .net framework remove the interface table and generate association with table mapping to it which is many-to-many.
I need role name how I can get it in this kind of model ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
aspnet_Roles
是aspnet_User
实体上的集合导航属性,并且SourceRoleName
是aspnet_Role
实体的映射属性,则必须重写它就像:如果您的
SourceRoleName
是aspnet_Role
实体中的计算属性(.NET 代码中的自定义属性),则您无法在 linq-to-entities 查询中使用它。您必须选择整个aspnet_Role
实体,然后访问其计算属性。If
aspnet_Roles
is collection navigation property on youraspnet_User
entity andSourceRoleName
is mapped property of youraspnet_Role
entity you must rewrite it like:If your
SourceRoleName
is computed property in youraspnet_Role
entity (custom property in .NET code) you can't use it in linq-to-entities query. You must select wholeaspnet_Role
entity and then access its computed property.