public void Apply(IDbModelBuilder modelBuilder) { if (PersistenceConfigurator.MappingsAssembly != null) { MapEntitiesFromMappingConfigurations(modelBuilder); } if (PersistenceConfigurator.EntititesAssembly != null) { MapEntitiesByDefaultConventions(modelBuilder); } }
private void MapEntitiesFromMappingConfigurations(IDbModelBuilder modelBuilder) { List <Type> list = (from type in PersistenceConfigurator.MappingsAssembly.GetTypes() .Where(p => p.Namespace != "SIGCOMT.Domain.Core") where type.BaseType != null && (type.BaseType.IsGenericType && (type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration <>))) select type).ToList <Type>(); foreach (Type type in list) { modelBuilder.AddConfiguration(type); Type baseType = type.BaseType; _alreadyMappedEntities.Add(baseType.GetGenericArguments()[0]); } }
private void MapEntitiesByDefaultConventions(IDbModelBuilder modelBuilder) { List <Type> list = (from type in PersistenceConfigurator.EntititesAssembly.GetExportedTypes() .Where(p => p.Namespace != "SIGCOMT.Domain.Core") where (type.BaseType != null && (type.BaseType.IsGenericType && (type.BaseType.GetGenericTypeDefinition() == typeof(Entity <>) || type.BaseType.GetGenericTypeDefinition() == typeof(EntityWithTypedId <>) || type.BaseType.GetGenericTypeDefinition() == typeof(EntityExtension <>) || type.BaseType.GetGenericTypeDefinition() == typeof(EntityBase)))) select type).ToList <Type>(); foreach (Type type in list) { if (!_alreadyMappedEntities.Contains(type)) { modelBuilder.AddEntity(type); } } }
/// <summary> /// Initializes a new instance of the <see cref="EFDataContext" /> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="dbModelBuilder">The database model builder.</param> public EFDataContext(IDbConnection connection, IDbModelBuilder dbModelBuilder) : base(connection.ConnectionString, dbModelBuilder.GetCompiled(connection)) { //_dbModelBuilder = dbModelBuilder; }