Setup base EF model and authentication #1
1 changed files with 18 additions and 18 deletions
|
@ -32,62 +32,62 @@ public class ApplicationDbContext : DbContext
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
// Company
|
// Company
|
||||||
modelBuilder.Entity<DbCompany>(c =>
|
modelBuilder.Entity<DbCompany>(entity =>
|
||||||
{
|
{
|
||||||
c.HasKey(c => c.Id);
|
entity.HasKey(c => c.Id);
|
||||||
|
|
||||||
c.HasMany(c => c.Products)
|
entity.HasMany(c => c.Products)
|
||||||
.WithOne(p => p.Company)
|
.WithOne(p => p.Company)
|
||||||
.HasForeignKey(p => p.CompanyId);
|
.HasForeignKey(p => p.CompanyId);
|
||||||
|
|
||||||
c.HasMany(c => c.CompanyRatings)
|
entity.HasMany(c => c.CompanyRatings)
|
||||||
.WithOne(cr => cr.Company)
|
.WithOne(cr => cr.Company)
|
||||||
.HasForeignKey(cr => cr.CompanyId);
|
.HasForeignKey(cr => cr.CompanyId);
|
||||||
|
|
||||||
c.Property(c => c.CompanyName)
|
entity.Property(c => c.CompanyName)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(50);
|
.HasMaxLength(50);
|
||||||
|
|
||||||
c.HasIndex(c => c.CompanyName)
|
entity.HasIndex(c => c.CompanyName)
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
// to do: index by Sum / Count
|
// to do: index by Sum / Count
|
||||||
});
|
});
|
||||||
|
|
||||||
// Company Rating
|
// Company Rating
|
||||||
modelBuilder.Entity<DbCompanyRating>(cr =>
|
modelBuilder.Entity<DbCompanyRating>(entity =>
|
||||||
{
|
{
|
||||||
cr.HasKey(cr => new { cr.UserId, cr.CompanyId });
|
entity.HasKey(cr => new { cr.UserId, cr.CompanyId });
|
||||||
|
|
||||||
cr.HasOne(cr => cr.User)
|
entity.HasOne(cr => cr.User)
|
||||||
.WithMany(u => u.CompanyRatings);
|
.WithMany(u => u.CompanyRatings);
|
||||||
|
|
||||||
cr.HasOne(cr => cr.Company)
|
entity.HasOne(cr => cr.Company)
|
||||||
.WithMany(c => c.CompanyRatings);
|
.WithMany(c => c.CompanyRatings);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Company Table
|
// Company Table
|
||||||
modelBuilder.Entity<DbCompanyTable>(ct =>
|
modelBuilder.Entity<DbCompanyTable>(entity =>
|
||||||
{
|
{
|
||||||
ct.HasKey(ct => ct.Id);
|
entity.HasKey(ct => ct.Id);
|
||||||
|
|
||||||
ct.HasMany(ct => ct.Companies)
|
entity.HasMany(ct => ct.Companies)
|
||||||
.WithOne(c => c.CompanyTable)
|
.WithOne(c => c.CompanyTable)
|
||||||
.HasForeignKey(c => c.CompanyTableId);
|
.HasForeignKey(c => c.CompanyTableId);
|
||||||
|
|
||||||
ct.HasIndex(ct => ct.CompanyTableName)
|
entity.HasIndex(ct => ct.CompanyTableName)
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Company Table View
|
// Company Table View
|
||||||
modelBuilder.Entity<DbCompanyTableView>(ctv =>
|
modelBuilder.Entity<DbCompanyTableView>(entity =>
|
||||||
{
|
{
|
||||||
ctv.HasKey(ctv => ctv.Id);
|
entity.HasKey(ctv => ctv.Id);
|
||||||
|
|
||||||
ctv.HasMany(ctv => ctv.CompanyTables)
|
entity.HasMany(ctv => ctv.CompanyTables)
|
||||||
.WithMany();
|
.WithMany();
|
||||||
|
|
||||||
ctv.HasMany(ctv => ctv.Users)
|
entity.HasMany(ctv => ctv.Users)
|
||||||
.WithMany(u => u.CompanyTableViews);
|
.WithMany(u => u.CompanyTableViews);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue