Reputation: 2686
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 ?
Upvotes: 0
Views: 440
Reputation: 364409
If aspnet_Roles
is collection navigation property on your aspnet_User
entity and SourceRoleName
is mapped property of your aspnet_Role
entity you must rewrite it like:
var q = (from m in context.aspnet_Users
where m.UserName.Equals(username)
select new
{
m,
m.aspnet_Roles.Select(r => r.SourceRoleName)
})
.FirstOrDefault();
If your SourceRoleName
is computed property in your aspnet_Role
entity (custom property in .NET code) you can't use it in linq-to-entities query. You must select whole aspnet_Role
entity and then access its computed property.
Upvotes: 2