Writing relations into customer and contact
This commit is contained in:
@@ -16,4 +16,6 @@ public class Contact
|
|||||||
|
|
||||||
public int CommunicationId { get; set; }
|
public int CommunicationId { get; set; }
|
||||||
public Communication? Communication { get; set; }
|
public Communication? Communication { get; set; }
|
||||||
|
|
||||||
|
public List<CustomerContact>? CustomerContacts { get; set; }
|
||||||
}
|
}
|
@@ -13,4 +13,6 @@ public class Customer
|
|||||||
|
|
||||||
public int ContactId { get; set; }
|
public int ContactId { get; set; }
|
||||||
public Contact? Contact { get; set; }
|
public Contact? Contact { get; set; }
|
||||||
|
|
||||||
|
public List<CustomerContact>? CustomerContacts { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,7 @@ public class PyroFetesDbContext : DbContext
|
|||||||
"Server=romaric-thibault.fr;" +
|
"Server=romaric-thibault.fr;" +
|
||||||
"Database=PyroFetes;" +
|
"Database=PyroFetes;" +
|
||||||
"User Id=pyrofetes;" +
|
"User Id=pyrofetes;" +
|
||||||
"Password=Onto9-Cage-Afflicted;" +
|
"Password=Crablike8-Fringe-Swimmable;" +
|
||||||
"TrustServerCertificate=true;";
|
"TrustServerCertificate=true;";
|
||||||
|
|
||||||
optionsBuilder.UseSqlServer(connectionString);
|
optionsBuilder.UseSqlServer(connectionString);
|
||||||
@@ -66,18 +66,28 @@ public class PyroFetesDbContext : DbContext
|
|||||||
// Models customization
|
// Models customization
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
// Relation SourceWarehouse
|
|
||||||
modelBuilder.Entity<Movement>()
|
modelBuilder.Entity<Movement>()
|
||||||
.HasOne(m => m.SourceWarehouse)
|
.HasOne(m => m.SourceWarehouse)
|
||||||
.WithMany(w => w.MovementsSource)
|
.WithMany(w => w.MovementsSource)
|
||||||
.HasForeignKey(m => m.SourceWarehouseId)
|
.HasForeignKey(m => m.SourceWarehouseId)
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
// Relation DestinationWarehouse
|
|
||||||
modelBuilder.Entity<Movement>()
|
modelBuilder.Entity<Movement>()
|
||||||
.HasOne(m => m.DestinationWarehouse)
|
.HasOne(m => m.DestinationWarehouse)
|
||||||
.WithMany(w => w.MovementsDestination)
|
.WithMany(w => w.MovementsDestination)
|
||||||
.HasForeignKey(m => m.DestinationWarehouseId)
|
.HasForeignKey(m => m.DestinationWarehouseId)
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
|
modelBuilder.Entity<CustomerContact>()
|
||||||
|
.HasOne(cc => cc.Customer)
|
||||||
|
.WithMany(c => c.CustomerContacts)
|
||||||
|
.HasForeignKey(cc => cc.CustomerId)
|
||||||
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
|
|
||||||
|
modelBuilder.Entity<CustomerContact>()
|
||||||
|
.HasOne(cc => cc.Contact)
|
||||||
|
.WithMany(c => c.CustomerContacts)
|
||||||
|
.HasForeignKey(cc => cc.ContactId)
|
||||||
|
.OnDelete(DeleteBehavior.NoAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user