Merge branch 'EntityFrameworkSetup' into EntityFrameworkSetupPropertyMap
# Conflicts: # DrinkRateAPI/Contexts/ApplicationDbContext.cs
This commit is contained in:
commit
0a4c4abcbc
1 changed files with 55 additions and 0 deletions
|
@ -154,5 +154,60 @@ public class ApplicationDbContext : DbContext
|
|||
entity.HasMany(ptv => ptv.Users)
|
||||
.WithMany(u => u.ProductTableViews);
|
||||
});
|
||||
|
||||
// User
|
||||
modelBuilder.Entity<DbUser>(entity =>
|
||||
{
|
||||
entity.HasKey(u => u.Id);
|
||||
|
||||
entity.HasMany(u => u.CompanyTableViews)
|
||||
.WithMany(ctv => ctv.Users);
|
||||
|
||||
entity.HasMany(u => u.ProductTableViews)
|
||||
.WithMany(ptv => ptv.Users);
|
||||
|
||||
entity.HasMany(u => u.CompanyRatings)
|
||||
.WithOne(cr => cr.User)
|
||||
.HasForeignKey(cr => cr.UserId);
|
||||
|
||||
entity.HasMany(u => u.ProductRatings)
|
||||
.WithOne(pr => pr.User)
|
||||
.HasForeignKey(pr => pr.UserId);
|
||||
|
||||
entity.HasMany(u => u.UserCompanyTableStats)
|
||||
.WithOne(ucts => ucts.User)
|
||||
.HasForeignKey(ucts => ucts.UserId);
|
||||
|
||||
entity.HasMany(u => u.UserProductTableStats)
|
||||
.WithOne(upts => upts.User)
|
||||
.HasForeignKey(upts => upts.UserId);
|
||||
|
||||
entity.HasIndex(u => u.UserName)
|
||||
.IsUnique();
|
||||
});
|
||||
|
||||
// User Company Table Stat
|
||||
modelBuilder.Entity<DbUserCompanyTableStat>(entity =>
|
||||
{
|
||||
entity.HasKey(ucts => new { ucts.UserId, ucts.CompanyTableId });
|
||||
|
||||
entity.HasOne(ucts => ucts.User)
|
||||
.WithMany(u => u.UserCompanyTableStats);
|
||||
|
||||
entity.HasOne(ucts => ucts.CompanyTable)
|
||||
.WithMany();
|
||||
});
|
||||
|
||||
// User Product Table Stat
|
||||
modelBuilder.Entity<DbUserProductTableStat>(entity =>
|
||||
{
|
||||
entity.HasKey(upts => new { upts.UserId, upts.ProductTableId });
|
||||
|
||||
entity.HasOne(upts => upts.User)
|
||||
.WithMany(u => u.UserProductTableStats);
|
||||
|
||||
entity.HasOne(upts => upts.ProductTable)
|
||||
.WithMany();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue