这是ApplicationUser:
public class ApplicationUser : IdentityUser<long>
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public UserTypes Type { get; set; }
public string FullName { get { return $"{Firstname ?? ""} {Lastname ?? ""}".Trim(); } }
}我们有3种不同的UserTypes (提供者、支持者、NormalUser (即ApplicationUser))
public class Provider : ApplicationUser{
// Provider related virtual Icollections
}
public class Supporter : ApplicationUser{
// Supporter related virtual Icollections
}现在,在ApplicationDbContext中,我希望在ApplicationUser旁边有这些DbSet:
public virtual DbSet<Provider> Providers{get;set;}
public virtual DbSet<Supporter> Supporters{get;set;}哪个DbSet<Provider>应该返回其UserTypes等于2的ApplicationUsers (例如)
发布于 2017-01-10 07:54:11
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public ApplicationDbContext()
: base()
{
}
public virtual IEnumerable<Provider> Providers
{
get
{
return (IEnumerable<Provider>)Users.Where(z => z.Type == UserTypes.Provider).AsEnumerable();
}
}
}https://stackoverflow.com/questions/41563151
复制相似问题