SHARE
TWEET

Untitled

a guest Mar 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  2.     {
  3.         RunConventions(modelBuilder, typeof(GalaxyUserMap));
  4.     }
  5.      
  6. public void RunConventions(DbModelBuilder modelBuilder, Type assemblyClassType)
  7.     {
  8.         // Change default conventions for cascade deletes
  9.         modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
  10.  
  11.         // Id property in everyclass is named class + Id  (i.e CustomerId, JobId, VendorId)
  12.         // Id is always first column in table
  13.         // Could also explicitly determine as key using .Configure(p => p.IsKey() but EF already looks for property of name Id as primary key
  14.         modelBuilder.Properties()
  15.           .Where(p => p.Name == "Id")
  16.           .Configure(p => p.HasColumnOrder(0).HasColumnName((p.ClrPropertyInfo.ReflectedType == null ? "" : p.ClrPropertyInfo.ReflectedType.Name) + "Id"));
  17.  
  18.         // Add Domain Entity Mapping Configurations
  19.         var typesToRegister = Assembly.GetAssembly(assemblyClassType).GetTypes()
  20.           .Where(type => type.Namespace != null);
  21.         foreach (Type type in typesToRegister)
  22.         {
  23.             dynamic configurationInstance = Activator.CreateInstance(type);
  24.             modelBuilder.Configurations.Add(configurationInstance);
  25.         }
  26.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top