2017-01-10 2 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 나는이 응용 프로그램 옆에 DbSet을 갖고 싶습니다.

public virtual DbSet<Provider> Providers{get;set;} 
public virtual DbSet<Supporter> Supporters{get;set;} 

어떤 DbSet<Provider> 반환해야합니다 그들의 UserTypes이 동일 ApplicationUsers 있음 (예를 들어) 2

+0

UserTypes의 속성은 무엇인가? –

+0

@ H.Herzl 잘 열거 형'{정상 = 1, 공급자 = 2, 지원자 = 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(); 
       } 
      } 
     }