Setup base EF model and authentication #1

Merged
Jiri merged 17 commits from EntityFrameworkSetup into main 2025-08-09 17:20:48 +00:00
Showing only changes of commit 53df5dcdc1 - Show all commits

View file

@ -90,5 +90,69 @@ public class ApplicationDbContext : DbContext
entity.HasMany(ctv => ctv.Users) entity.HasMany(ctv => ctv.Users)
.WithMany(u => u.CompanyTableViews); .WithMany(u => u.CompanyTableViews);
}); });
// Product
modelBuilder.Entity<DbProduct>(entity =>
{
entity.HasKey(p => p.Id);
entity.HasOne(p => p.ProductTable)
.WithMany(pt => pt.Products)
.HasForeignKey(p => p.ProductTableId);
entity.HasOne(p => p.Company)
.WithMany(c => c.Products)
.HasForeignKey(p => p.CompanyId);
entity.HasMany(p => p.ProductRatings)
.WithOne(pr => pr.Product)
.HasForeignKey(pr => pr.ProductId);
entity.Property(p => p.ProductName)
.IsRequired()
.HasMaxLength(50);
entity.HasIndex(c => c.ProductName)
.IsUnique();
// to do: index by Sum / Count
});
// Product Rating
modelBuilder.Entity<DbProductRating>(entity =>
{
entity.HasKey(pr => new { pr.UserId, pr.ProductId });
entity.HasOne(pr => pr.User)
.WithMany(u => u.ProductRatings);
entity.HasOne(pr => pr.Product)
.WithMany(p => p.ProductRatings);
});
// Product Table
modelBuilder.Entity<DbProductTable>(entity =>
{
entity.HasKey(pt => pt.Id);
entity.HasMany(pt => pt.Products)
.WithOne(p => p.ProductTable)
.HasForeignKey(p => p.ProductTableId);
entity.HasIndex(pt => pt.ProductTableName)
.IsUnique();
});
// Product Table View
modelBuilder.Entity<DbProductTableView>(entity =>
{
entity.HasKey(ptv => ptv.Id);
entity.HasMany(ptv => ptv.ProductTables)
.WithMany();
entity.HasMany(ptv => ptv.Users)
.WithMany(u => u.ProductTableViews);
});
} }
} }