Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1.  
  2. using VehicleRental.Domain;
  3. using System.Data.Entity;
  4.  
  5. namespace VehicleRental.Persistence
  6. {
  7. public class VehicleRentalDbContext : DbContext
  8. {
  9. public VehicleRentalDbContext() : base("Name=VehicleRentalDbConnection") //this is the connection string name
  10. {
  11. /*
  12. See DbContext.Configuration documentation
  13. */
  14. Configuration.ProxyCreationEnabled = true;
  15. Configuration.LazyLoadingEnabled = true;
  16. }
  17.  
  18. static VehicleRentalDbContext()
  19. {
  20. //Database.SetInitializer<VehicleRentalDbContext>(new CreateDatabaseIfNotExists<VehicleRentalDbContext>());
  21. Database.SetInitializer<VehicleRentalDbContext>(new DropCreateDatabaseIfModelChanges<VehicleRentalDbContext>());
  22. //Database.SetInitializer<VehicleRentalDbContext>(new DropCreateDatabaseAlways<VehicleRentalDbContext>());
  23. //Database.SetInitializer<VehicleRentalDbContext>(new VehicleRentalDbInitializer());
  24. //Database.SetInitializer(new NullDatabaseInitializer<VehicleRentalDbContext>());
  25. }
  26.  
  27. public IDbSet<BranchOffice> BranchOffices { get; set; }
  28. public IDbSet<Reservation> Reservations { get; set; }
  29. public IDbSet<Category> Categories { get; set; }
  30. public IDbSet<Person> People { get; set; }
  31. public IDbSet<Customer> Customers { get; set; }
  32. public IDbSet<CreditCard> CreditCards { get; set; }
  33.  
  34. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  35. {
  36. // Primary keys with non conventional name
  37. /*
  38. modelBuilder.Entity<Person>().HasKey(p => p.Dni);
  39. modelBuilder.Entity<Customer>().HasKey(c => c.Dni);
  40. modelBuilder.Entity<CreditCard>().HasKey(c => c.Digits);
  41. */
  42. // Classes with more than one relationship
  43. /*
  44. modelBuilder.Entity<Reservation>().HasRequired(r => r.PickUpOffice).WithMany(o => o.PickUpReservations).WillCascadeOnDelete(false);
  45. modelBuilder.Entity<Reservation>().HasRequired(r => r.ReturnOffice).WithMany(o => o.ReturnReservations).WillCascadeOnDelete(false);
  46. */
  47. }
  48.  
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement