Advertisement
Guest User

BusStationSystem

a guest
Nov 25th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. public class TicketConfiguration : IEntityTypeConfiguration<Ticket>
  2.     {
  3.         public void Configure(EntityTypeBuilder<Ticket> builder)
  4.         {
  5.  
  6.             //Each ticket is bought from a customer for a certain trip. ??
  7.  
  8.  
  9.             builder.HasKey(t => new { t.TicketId, t.CustomerId, t.TripId });
  10.  
  11.             builder.HasOne(c => c.Customer)
  12.                 .WithOne(t => t.Ticket)
  13.                 .HasForeignKey<Ticket>(ct => ct.CustomerId)
  14.                 .OnDelete(DeleteBehavior.Restrict);
  15.  
  16.             builder.HasOne(tr => tr.Trip)
  17.                 .WithOne(t => t.Ticket)
  18.                 .HasForeignKey<Ticket>(tr => tr.TripId)
  19.                 .OnDelete(DeleteBehavior.Restrict);
  20.         }
  21.     }
  22.  
  23.  
  24. public class TripConfiguration : IEntityTypeConfiguration<Trip>
  25.     {
  26.         public void Configure(EntityTypeBuilder<Trip> builder)
  27.         {
  28.             //Every trip has an origin and a destination ???
  29.  
  30.  
  31.             builder.HasKey(tr => tr.TripId);
  32.  
  33.             builder.HasOne(bc => bc.BusCompany)
  34.                 .WithMany(tr => tr.Trips)
  35.                 .HasForeignKey(bc => bc.BusCompanyId)
  36.                 .OnDelete(DeleteBehavior.Restrict);
  37.         }
  38.     }
  39.  
  40.  
  41. public class BankAccountCongiguration : IEntityTypeConfiguration<BankAccount>
  42.     {
  43.         public void Configure(EntityTypeBuilder<BankAccount> builder)
  44.         {
  45.             //Bank account can be owned by one customer and each customer can own only one bank account. ??
  46.  
  47.  
  48.             builder.HasKey(b => new { b.BankAccountId, b.CustomerId });
  49.                
  50.             builder.HasOne(c => c.Customer)
  51.                 .WithOne(b => b.BankAccount)
  52.                 .HasForeignKey<BankAccount>(c => c.CustomerId)
  53.                 .OnDelete(DeleteBehavior.Restrict);
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement