Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TicketConfiguration : IEntityTypeConfiguration<Ticket>
- {
- public void Configure(EntityTypeBuilder<Ticket> builder)
- {
- //Each ticket is bought from a customer for a certain trip. ??
- builder.HasKey(t => new { t.TicketId, t.CustomerId, t.TripId });
- builder.HasOne(c => c.Customer)
- .WithOne(t => t.Ticket)
- .HasForeignKey<Ticket>(ct => ct.CustomerId)
- .OnDelete(DeleteBehavior.Restrict);
- builder.HasOne(tr => tr.Trip)
- .WithOne(t => t.Ticket)
- .HasForeignKey<Ticket>(tr => tr.TripId)
- .OnDelete(DeleteBehavior.Restrict);
- }
- }
- public class TripConfiguration : IEntityTypeConfiguration<Trip>
- {
- public void Configure(EntityTypeBuilder<Trip> builder)
- {
- //Every trip has an origin and a destination ???
- builder.HasKey(tr => tr.TripId);
- builder.HasOne(bc => bc.BusCompany)
- .WithMany(tr => tr.Trips)
- .HasForeignKey(bc => bc.BusCompanyId)
- .OnDelete(DeleteBehavior.Restrict);
- }
- }
- public class BankAccountCongiguration : IEntityTypeConfiguration<BankAccount>
- {
- public void Configure(EntityTypeBuilder<BankAccount> builder)
- {
- //Bank account can be owned by one customer and each customer can own only one bank account. ??
- builder.HasKey(b => new { b.BankAccountId, b.CustomerId });
- builder.HasOne(c => c.Customer)
- .WithOne(b => b.BankAccount)
- .HasForeignKey<BankAccount>(c => c.CustomerId)
- .OnDelete(DeleteBehavior.Restrict);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement