【发布时间】:2014-12-01 06:42:11
【问题描述】:
我正在使用 ASP.NET Identity 2.0,据我了解,它使用实体框架。我很好奇为什么在 DB 上下文中没有设置 DbSet<ApplicationUser> 属性?如果它们没有在上下文中逐字指定,这如何仍然使用相同的上下文。这些是否位于基类上?
我想编写一个从 ApplicationUser -> ApplicationRoles -> ApplicationRole (这是一个自引用属性)的 Linq 查询,并想为此使用 Linq to Entities,但是我找不到在 Google 上有很多关于这方面的内容,并希望在编写 Linq 查询之前确保我的上下文是正确的。
ApplicationUser.cs
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public ICollection<ApplicationUserRole> UserRoles { get; set; }
}
ApplicationRole.cs
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name)
: base(name)
{ }
public ApplicationRole(string name, string description)
: base(name)
{
this.Description = description;
}
public string Description { get; set; }
public virtual ApplicationRole ParentRole { get; set; }
}
【问题讨论】:
标签: c# asp.net linq entity-framework asp.net-mvc-5