public static PetaPocoMappings BuildMappingsFromMaps(params IPetaPocoMap[] petaPocoMaps) { var petaPocoConfig = new PetaPocoMappings(); foreach (var petaPocoMap in petaPocoMaps) { var type = petaPocoMap.TypeDefinition.Type; petaPocoConfig.Config[type] = petaPocoMap.TypeDefinition; } return(petaPocoConfig); }
public static PetaPocoMappings Scan(Action <IPetaPocoConventionScanner> scanner) { var scannerSettings = ProcessSettings(scanner); if (scannerSettings.Lazy) { var lazyPetaPocoMappings = new PetaPocoMappings(); SetFactory(lazyPetaPocoMappings, scanner); return(lazyPetaPocoMappings); } return(CreateMappings(scannerSettings, null)); }
private static PetaPocoMappings CreateMappings(PetaPocoConventionScannerSettings scannerSettings, Type[] typesOverride) { var types = typesOverride ?? FindTypes(scannerSettings); var config = new Dictionary <Type, PetaPocoTypeDefinition>(); foreach (var type in types) { var petaPocoDefn = new PetaPocoTypeDefinition(type) { AutoIncrement = scannerSettings.PrimaryKeysAutoIncremented(type), PrimaryKey = scannerSettings.PrimaryKeysNamed(type), TableName = scannerSettings.TablesNamed(type), SequenceName = scannerSettings.SequencesNamed(type), }; foreach (var prop in type.GetProperties()) { var column = new PetaPocoColumnDefinition(); column.PropertyInfo = prop; column.DbColumnName = scannerSettings.PropertiesNamed(prop); column.IgnoreColumn = scannerSettings.IgnorePropertiesWhere.Any(x => x.Invoke(prop)); column.ResultColumn = scannerSettings.ResultPropertiesWhere(prop); column.VersionColumn = scannerSettings.VersionPropertiesWhere(prop); petaPocoDefn.ColumnConfiguration.Add(prop.Name, column); } config.Add(type, petaPocoDefn); } MergeOverrides(config, scannerSettings.MappingOverrides); var petaPocoMappings = new PetaPocoMappings { Config = config }; SetFactory(petaPocoMappings, null); return(petaPocoMappings); }
private static void SetFactory(PetaPocoMappings mappings, Action <IPetaPocoConventionScanner> scanner) { var maps = mappings; var scana = scanner; Database.PocoDataFactory = t => { if (maps != null) { if (maps.Config.ContainsKey(t)) { return(new FluentMappingsPocoData(t, mappings.Config[t])); } if (scana != null) { var settings = ProcessSettings(scana); var typeMapping = CreateMappings(settings, new[] { t }); return(new FluentMappingsPocoData(t, typeMapping.Config[t])); } } return(new Database.PocoData(t)); }; }
public void OverrideMappingsWith(params IPetaPocoMap[] maps) { var mappings = PetaPocoMappings.BuildMappingsFromMaps(maps); _scannerSettings.MappingOverrides = mappings; }
public void OverrideMappingsWith(PetaPocoMappings mappings) { _scannerSettings.MappingOverrides = mappings; }
private static void MergeOverrides(Dictionary <Type, PetaPocoTypeDefinition> config, PetaPocoMappings overrideMappings) { if (overrideMappings == null) { return; } foreach (var overrideTypeDefinition in overrideMappings.Config) { if (!config.ContainsKey(overrideTypeDefinition.Key)) { continue; } var convTableDefinition = config[overrideTypeDefinition.Key]; convTableDefinition.PrimaryKey = overrideTypeDefinition.Value.PrimaryKey ?? convTableDefinition.PrimaryKey; convTableDefinition.SequenceName = overrideTypeDefinition.Value.SequenceName ?? convTableDefinition.SequenceName; convTableDefinition.TableName = overrideTypeDefinition.Value.TableName ?? convTableDefinition.TableName; convTableDefinition.AutoIncrement = overrideTypeDefinition.Value.AutoIncrement ?? convTableDefinition.AutoIncrement; convTableDefinition.ExplicitColumns = overrideTypeDefinition.Value.ExplicitColumns ?? convTableDefinition.ExplicitColumns; foreach (var overrideColumnDefinition in overrideMappings.Config[overrideTypeDefinition.Key].ColumnConfiguration) { var convColDefinition = convTableDefinition.ColumnConfiguration[overrideColumnDefinition.Key]; convColDefinition.DbColumnName = overrideColumnDefinition.Value.DbColumnName ?? convColDefinition.DbColumnName; convColDefinition.IgnoreColumn = overrideColumnDefinition.Value.IgnoreColumn ?? convColDefinition.IgnoreColumn; convColDefinition.ResultColumn = overrideColumnDefinition.Value.ResultColumn ?? convColDefinition.ResultColumn; convColDefinition.VersionColumn = overrideColumnDefinition.Value.VersionColumn ?? convColDefinition.VersionColumn; convColDefinition.PropertyInfo = overrideColumnDefinition.Value.PropertyInfo ?? convColDefinition.PropertyInfo; } } }
public static void Configure(PetaPocoMappings mappings) { SetFactory(mappings, null); }
public static void Configure(params IPetaPocoMap[] petaPocoMaps) { var mappings = PetaPocoMappings.BuildMappingsFromMaps(petaPocoMaps); SetFactory(mappings, null); }