2017-01-10 7 views
0

これはApplicationUserです:私たちは3異なるUserTypesを持ってフィルタリングDbSet EntityFrameworkでCodeFirst

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(); } } 
} 

(プロバイダ、サポーター、あるNormalUser (ApplicationUser))で今

public class Provider : ApplicationUser{ 
    // Provider related virtual Icollections 
} 

public class Supporter : ApplicationUser{ 
    // Supporter related virtual Icollections 
} 

ApplicationDbContext私はこのアプリケーションをお気に入りに登録しています

public virtual DbSet<Provider> Providers{get;set;} 
public virtual DbSet<Supporter> Supporters{get;set;} 
DbSet<Provider>が自分 UserTypesは、(例えば)2に等しいという ApplicationUsersを返す必要があります

+0

UserTypesの性質は何ですか? –

+0

@H.Herzlそれはenum '{Normal = 1、Provider = 2、Supporter = 3}' –

+0

でしたか? var query = dbContext.Providers.Where(item => item.Type == UserTypes.Provider).ToList(); –

答えて

1
 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(); 
       } 
      } 
     } 
関連する問題