Upgrade EF models and add some EF mappings
This commit is contained in:
parent
b7996872cb
commit
2830d5dd48
167 changed files with 5950 additions and 59 deletions
|
@ -1,10 +1,71 @@
|
|||
using DrinkRateAPI.DbEntities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DrinkRateAPI.Contexts;
|
||||
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<DbContext> options) :
|
||||
base(options)
|
||||
{ }
|
||||
public DbSet<DbCompany> Companies { get; set; }
|
||||
public DbSet<DbCompanyRating> CompanyRatings { get; set; }
|
||||
public DbSet<DbCompanyTable> CompanyTables { get; set; }
|
||||
public DbSet<DbCompanyTableView> CompanyTableViews { get; set; }
|
||||
|
||||
public DbSet<DbProduct> Product { get; set; }
|
||||
public DbSet<DbProductRating> ProductRating { get; set; }
|
||||
public DbSet<DbProductTable> ProductTable { get; set; }
|
||||
public DbSet<DbProductTableView> ProductTableView { get; set; }
|
||||
|
||||
public DbSet<DbUser> Users { get; set; }
|
||||
public DbSet<DbUserCompanyTableStat> UserCompanyTableStats { get; set; }
|
||||
public DbSet<DbUserProductTableStat> UserProductTableStats { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
optionsBuilder.UseNpgsql(configuration.GetConnectionString("Local"));
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Company
|
||||
modelBuilder.Entity<DbCompany>(c =>
|
||||
{
|
||||
c.HasKey(c => c.Id);
|
||||
|
||||
c.HasMany(c => c.Products)
|
||||
.WithOne(p => p.Company)
|
||||
.HasForeignKey(p => p.CompanyId);
|
||||
|
||||
c.HasMany(c => c.CompanyRatings)
|
||||
.WithOne(cr => cr.Company)
|
||||
.HasForeignKey(cr => cr.CompanyId);
|
||||
|
||||
c.Property(c => c.CompanyName)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
c.HasIndex(c => c.CompanyName)
|
||||
.IsUnique();
|
||||
|
||||
// to do: index by Sum / Count
|
||||
});
|
||||
|
||||
// Company Rating
|
||||
modelBuilder.Entity<DbCompanyRating>(cr =>
|
||||
{
|
||||
cr.HasKey(cr => new { cr.UserId, cr.CompanyId });
|
||||
|
||||
cr.HasOne(cr => cr.User)
|
||||
.WithMany(u => u.CompanyRatings);
|
||||
|
||||
cr.HasOne(cr => cr.Company)
|
||||
.WithMany(c => c.CompanyRatings);
|
||||
});
|
||||
|
||||
// to do: othe objects
|
||||
}
|
||||
}
|
|
@ -4,11 +4,16 @@ public class DbCompany
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid TableId { get; set; }
|
||||
public Guid CompanyTableId { get; set; }
|
||||
public DbCompanyTable CompanyTable { get; set; }
|
||||
|
||||
public ICollection<DbProduct> Products { get; set; }
|
||||
|
||||
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
|
||||
|
||||
public string CompanyName { get; set; }
|
||||
|
||||
public long RatingSum { get; set; }
|
||||
|
||||
public long RatingCount { get; set; }
|
||||
}
|
|
@ -3,10 +3,10 @@ namespace DrinkRateAPI.DbEntities;
|
|||
public class DbCompanyRating
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public DbUser User { get; set; }
|
||||
|
||||
public Guid CompanyId { get; set; }
|
||||
|
||||
public Guid CompanyTableId { get; set; }
|
||||
public DbCompany Company { get; set; }
|
||||
|
||||
public byte Rating { get; set; }
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ namespace DrinkRateAPI.DbEntities;
|
|||
|
||||
public class DbCompanyTable
|
||||
{
|
||||
public string TableName { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public ICollection<DbCompany> Companies { get; set; }
|
||||
|
||||
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
|
||||
public string CompanyTable { get; set; }
|
||||
}
|
|
@ -4,7 +4,7 @@ public class DbCompanyTableView
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid CompanyTableId { get; set; }
|
||||
public ICollection<DbCompanyTable> CompanyTables { get; set; }
|
||||
|
||||
public ICollection<DbUser> Users { get; set; }
|
||||
|
||||
|
|
|
@ -4,9 +4,17 @@ public class DbProduct
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid CompanyId { get; set; }
|
||||
public Guid ProductTableId { get; set; }
|
||||
public DbProductTable ProductTable { get; set; }
|
||||
|
||||
public Guid TableId { get; set; }
|
||||
public Guid CompanyId { get; set; }
|
||||
public DbCompany Company { get; set; }
|
||||
|
||||
public ICollection<DbProductRating> ProductRatings { get; set; }
|
||||
|
||||
public string ProductName { get; set; }
|
||||
|
||||
public long RatingSum { get; set; }
|
||||
|
||||
public long RatingCount { get; set; }
|
||||
}
|
|
@ -3,10 +3,10 @@ namespace DrinkRateAPI.DbEntities;
|
|||
public class DbProductRating
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public DbUser User { get; set; }
|
||||
|
||||
public Guid ProductId { get; set; }
|
||||
|
||||
public Guid ProductTableId { get; set; }
|
||||
public DbProduct Product { get; set; }
|
||||
|
||||
public byte Rating { get; set; }
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@ public class DbProductTable
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public string TableName { get; set; }
|
||||
|
||||
public ICollection<DbProduct> Products { get; set; }
|
||||
|
||||
public ICollection<DbProductRating> ProductRatings { get; set; }
|
||||
public string ProductTable { get; set; }
|
||||
}
|
|
@ -4,10 +4,9 @@ public class DbProductTableView
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid ProductTableId { get; set; }
|
||||
public ICollection<DbProductTable> ProductTables { get; set; }
|
||||
|
||||
public ICollection<DbUser> Users { get; set; }
|
||||
|
||||
// to do: permission types
|
||||
|
||||
}
|
|
@ -10,8 +10,12 @@ public class DbUser
|
|||
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
|
||||
public ICollection<DbProductRating> ProductRatings { get; set; }
|
||||
|
||||
public ICollection<DbUserCompanyTableStats> UserCompanyTableStats { get; set; }
|
||||
public ICollection<DbUserProductTableStats> UserProductTableStats { get; set; }
|
||||
public ICollection<DbUserCompanyTableStat> UserCompanyTableStats { get; set; }
|
||||
public ICollection<DbUserProductTableStat> UserProductTableStats { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
16
DrinkRateAPI/DbEntities/DbUserCompanyTableStat.cs
Normal file
16
DrinkRateAPI/DbEntities/DbUserCompanyTableStat.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
namespace DrinkRateAPI.DbEntities;
|
||||
|
||||
public class DbUserCompanyTableStat
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public DbUser User { get; set; }
|
||||
|
||||
public Guid CompanyTableId { get; set; }
|
||||
public DbCompanyTable CompanyTable { get; set; }
|
||||
|
||||
public int RatingCount { get; set; }
|
||||
|
||||
public int HighestRatingCount { get; set; }
|
||||
|
||||
public int Credits { get; set; }
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
namespace DrinkRateAPI.DbEntities;
|
||||
|
||||
public class DbUserCompanyTableStats
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
public Guid CompanyTabelId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int MaxCount { get; set; }
|
||||
|
||||
public int Credits { get; set; }
|
||||
}
|
16
DrinkRateAPI/DbEntities/DbUserProductTableStat.cs
Normal file
16
DrinkRateAPI/DbEntities/DbUserProductTableStat.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
namespace DrinkRateAPI.DbEntities;
|
||||
|
||||
public class DbUserProductTableStat
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public DbUser User { get; set; }
|
||||
|
||||
public Guid ProductTableId { get; set; }
|
||||
public DbProductTable ProductTable { get; set; }
|
||||
|
||||
public int RatingCount { get; set; }
|
||||
|
||||
public int HighestRatingCount { get; set; }
|
||||
|
||||
public int Credits { get; set; }
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
namespace DrinkRateAPI.DbEntities;
|
||||
|
||||
public class DbUserProductTableStats
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
public Guid ProductTabelId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int MaxCount { get; set; }
|
||||
|
||||
public int Credits { get; set; }
|
||||
}
|
|
@ -9,7 +9,13 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.8" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
29
DrinkRateAPI/Migrations/20250809085523_250809_ApplicationInit.Designer.cs
generated
Normal file
29
DrinkRateAPI/Migrations/20250809085523_250809_ApplicationInit.Designer.cs
generated
Normal file
|
@ -0,0 +1,29 @@
|
|||
// <auto-generated />
|
||||
using DrinkRateAPI.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DrinkRateAPI.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20250809085523_250809_ApplicationInit")]
|
||||
partial class _250809_ApplicationInit
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DrinkRateAPI.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class _250809_ApplicationInit : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
26
DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
26
DrinkRateAPI/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
// <auto-generated />
|
||||
using DrinkRateAPI.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DrinkRateAPI.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,5 +4,8 @@
|
|||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,5 +5,8 @@
|
|||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead"
|
||||
}
|
||||
}
|
||||
|
|
BIN
DrinkRateAPI/bin/Debug/net9.0/Azure.Core.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Azure.Core.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Azure.Identity.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Azure.Identity.dll
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Humanizer.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Humanizer.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Bcl.AsyncInterfaces.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Bcl.AsyncInterfaces.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Build.Locator.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Build.Locator.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.CodeAnalysis.CSharp.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.CodeAnalysis.CSharp.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.CodeAnalysis.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.CodeAnalysis.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Data.SqlClient.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Data.SqlClient.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Identity.Client.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Identity.Client.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.IdentityModel.Tokens.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.IdentityModel.Tokens.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.SqlServer.Server.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.SqlServer.Server.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Win32.SystemEvents.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Microsoft.Win32.SystemEvents.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Mono.TextTemplating.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Mono.TextTemplating.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/Npgsql.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/Npgsql.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.ClientModel.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.ClientModel.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.CodeDom.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.CodeDom.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Convention.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Convention.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Hosting.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Hosting.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Runtime.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.Runtime.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.TypedParts.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Composition.TypedParts.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Drawing.Common.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Drawing.Common.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Memory.Data.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Memory.Data.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Runtime.Caching.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Runtime.Caching.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Security.Permissions.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Security.Permissions.dll
Normal file
Binary file not shown.
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Windows.Extensions.dll
Normal file
BIN
DrinkRateAPI/bin/Debug/net9.0/System.Windows.Extensions.dll
Normal file
Binary file not shown.
|
@ -4,5 +4,8 @@
|
|||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,5 +5,8 @@
|
|||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"Local": "Host=localhost;Port=6942;Database=postgres;Username=postgres;Password=rum_beer_quests_mead"
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue