Created API Controllers (#1)
Removed strongly typed inventory objects Added EAV inventory types Added EAV object handling philosophy Added controllers Added EF Core migration integration Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WyvernInventory.Core.Models;
|
||||
|
||||
namespace WyvernInventory.Infrastructure.Data;
|
||||
|
||||
public class DBContext : DbContext
|
||||
{
|
||||
|
||||
public DBContext(DbContextOptions<DBContext> options) : base(options) {}
|
||||
|
||||
public DbSet<InventoryItem> InventoryItems => Set<InventoryItem>();
|
||||
public DbSet<InventoryAttributeDefinition> InventoryAttributeDefinitions => Set<InventoryAttributeDefinition>();
|
||||
public DbSet<InventoryAttributeValue> InventoryAttributeValues => Set<InventoryAttributeValue>();
|
||||
public DbSet<InventoryType> InventoryTypes => Set<InventoryType>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<InventoryItem>()
|
||||
.HasOne(_ => _.Type)
|
||||
.WithMany()
|
||||
.HasForeignKey(_ => _.TypeId);
|
||||
|
||||
modelBuilder.Entity<InventoryAttributeValue>()
|
||||
.HasOne(_ => _.Item)
|
||||
.WithMany(_ => _.AttributeValues)
|
||||
.HasForeignKey(_ => _.ItemId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<InventoryAttributeValue>()
|
||||
.HasOne(_ => _.AttributeDefinition)
|
||||
.WithMany()
|
||||
.HasForeignKey(_ => _.AttributeDefinitionId)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
modelBuilder.Entity<InventoryAttributeDefinition>()
|
||||
.HasOne(_ => _.Type)
|
||||
.WithMany(_ => _.AttributeDefinitions)
|
||||
.HasForeignKey(_ => _.TypeId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<InventoryAttributeValue>()
|
||||
.HasIndex(_ => new { _.ItemId, _.AttributeDefinitionId})
|
||||
.IsUnique();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user