Setup base EF model and authentication #1
1 changed files with 55 additions and 0 deletions
|
@ -90,5 +90,60 @@ public class ApplicationDbContext : DbContext
|
||||||
entity.HasMany(ctv => ctv.Users)
|
entity.HasMany(ctv => ctv.Users)
|
||||||
.WithMany(u => u.CompanyTableViews);
|
.WithMany(u => u.CompanyTableViews);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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