protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); #region ajustando FKs foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) { relationship.DeleteBehavior = DeleteBehavior.Restrict; /* * if (relationship.Properties.Count != 0) * { * var prop = relationship.Properties[0]; * var PTR = prop.PropertyInfo; * if (PTR != null) * { * * var attributes = PTR.CustomAttributes; * foreach (var attribute in attributes) * { * if (attribute.AttributeType.Name.ToLower() == "cascade") * { * relationship.DeleteBehavior = DeleteBehavior.Cascade; * } * } * } * } */ } #endregion //Dynamic Mapping by Reflection var typesToMapping = (from x in Assembly.GetExecutingAssembly().GetTypes() where x.IsClass && typeof(IMapping).IsAssignableFrom(x) select x).ToList(); foreach (var mapping in typesToMapping) { IMapping mappingClass = Activator.CreateInstance(mapping) as IMapping; mappingClass.OnModelCreating(modelBuilder); } }