diff --git a/PyroFetes/Models/Contact.cs b/PyroFetes/Models/Contact.cs index 3b0e762..958f52a 100644 --- a/PyroFetes/Models/Contact.cs +++ b/PyroFetes/Models/Contact.cs @@ -16,4 +16,6 @@ public class Contact public int CommunicationId { get; set; } public Communication? Communication { get; set; } + + public List? CustomerContacts { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Models/Customer.cs b/PyroFetes/Models/Customer.cs index d158621..98a49b0 100644 --- a/PyroFetes/Models/Customer.cs +++ b/PyroFetes/Models/Customer.cs @@ -13,4 +13,6 @@ public class Customer public int ContactId { get; set; } public Contact? Contact { get; set; } + + public List? CustomerContacts { get; set; } } diff --git a/PyroFetes/PyroFetesDbContext.cs b/PyroFetes/PyroFetesDbContext.cs index 29fc13b..2641f14 100644 --- a/PyroFetes/PyroFetesDbContext.cs +++ b/PyroFetes/PyroFetesDbContext.cs @@ -57,7 +57,7 @@ public class PyroFetesDbContext : DbContext "Server=romaric-thibault.fr;" + "Database=PyroFetes;" + "User Id=pyrofetes;" + - "Password=Onto9-Cage-Afflicted;" + + "Password=Crablike8-Fringe-Swimmable;" + "TrustServerCertificate=true;"; optionsBuilder.UseSqlServer(connectionString); @@ -66,18 +66,28 @@ public class PyroFetesDbContext : DbContext // Models customization protected override void OnModelCreating(ModelBuilder modelBuilder) { - // Relation SourceWarehouse modelBuilder.Entity() .HasOne(m => m.SourceWarehouse) .WithMany(w => w.MovementsSource) .HasForeignKey(m => m.SourceWarehouseId) .OnDelete(DeleteBehavior.Restrict); - - // Relation DestinationWarehouse + modelBuilder.Entity() .HasOne(m => m.DestinationWarehouse) .WithMany(w => w.MovementsDestination) .HasForeignKey(m => m.DestinationWarehouseId) .OnDelete(DeleteBehavior.Restrict); + + modelBuilder.Entity() + .HasOne(cc => cc.Customer) + .WithMany(c => c.CustomerContacts) + .HasForeignKey(cc => cc.CustomerId) + .OnDelete(DeleteBehavior.NoAction); + + modelBuilder.Entity() + .HasOne(cc => cc.Contact) + .WithMany(c => c.CustomerContacts) + .HasForeignKey(cc => cc.ContactId) + .OnDelete(DeleteBehavior.NoAction); } } \ No newline at end of file