Example #1
0
        private static Mappings CreateMappings(ConventionScannerSettings scannerSettings, Type[] typesOverride)
        {
            var types  = typesOverride ?? FindTypes(scannerSettings);
            var config = new Dictionary <Type, TypeDefinition>();

            foreach (var type in types)
            {
                var pocoDefn = new TypeDefinition(type)
                {
                    AutoIncrement   = scannerSettings.PrimaryKeysAutoIncremented(type),
                    PrimaryKey      = scannerSettings.PrimaryKeysNamed(type),
                    TableName       = scannerSettings.TablesNamed(type),
                    SequenceName    = scannerSettings.SequencesNamed(type),
                    ExplicitColumns = true
                };

                foreach (var prop in ReflectionUtils.GetFieldsAndPropertiesForClasses(type))
                {
                    var column = new ColumnDefinition();
                    column.MemberInfo        = prop;
                    column.DbColumnName      = scannerSettings.PropertiesNamed(prop);
                    column.DbColumnAlias     = scannerSettings.AliasNamed(prop);
                    column.IgnoreColumn      = scannerSettings.IgnorePropertiesWhere.Any(x => x.Invoke(prop));
                    column.DbColumnType      = scannerSettings.DbColumnTypesAs(prop);
                    column.ResultColumn      = scannerSettings.ResultPropertiesWhere(prop);
                    column.ComputedColumn    = scannerSettings.ComputedPropertiesWhere(prop);
                    column.VersionColumn     = scannerSettings.VersionPropertiesWhere(prop);
                    column.VersionColumnType = scannerSettings.VersionColumnTypeAs(prop);
                    column.ForceUtc          = scannerSettings.ForceDateTimesToUtcWhere(prop);

                    if (!pocoDefn.ColumnConfiguration.ContainsKey(prop.Name))
                    {
                        pocoDefn.ColumnConfiguration.Add(prop.Name, column);
                    }
                }

                config.Add(type, pocoDefn);
            }

            MergeOverrides(config, scannerSettings.MappingOverrides);

            //if (scannerSettings.OverrideWithAttributes)
            //{
            //    MergeAttributeOverrides(config);
            //}

            var pocoMappings = new Mappings {
                Config = config
            };

            return(pocoMappings);
        }
Example #2
0
        private static IEnumerable <Type> FindTypes(ConventionScannerSettings scannerSettings)
        {
            if (scannerSettings.TheCallingAssembly)
            {
                scannerSettings.Assemblies.Add(FindTheCallingAssembly());
            }

            var types = scannerSettings.Assemblies
                        .SelectMany(x => x.GetExportedTypes())
                        .Where(x => scannerSettings.IncludeTypes.All(y => y.Invoke(x)))
                        .Where(x => !x.IsNested && !typeof(Map <>).IsAssignableFrom(x) && !typeof(Mappings).IsAssignableFrom(x));

            return(types);
        }
        private static Mappings CreateMappings(ConventionScannerSettings scannerSettings, Type[] typesOverride)
        {
            var types = typesOverride ?? FindTypes(scannerSettings);
            var config = new Dictionary<Type, TypeDefinition>();

            foreach (var type in types)
            {
                var pocoDefn = new TypeDefinition(type)
                {
                    AutoIncrement = scannerSettings.PrimaryKeysAutoIncremented(type),
                    PrimaryKey = scannerSettings.PrimaryKeysNamed(type),
                    TableName = scannerSettings.TablesNamed(type),
                    SequenceName = scannerSettings.SequencesNamed(type),
                    ExplicitColumns = true
                };

                foreach (var prop in ReflectionUtils.GetFieldsAndPropertiesForClasses(type))
                {
                    var column = new ColumnDefinition();
                    column.MemberInfo = prop;
                    column.DbColumnName = scannerSettings.PropertiesNamed(prop);
                    column.DbColumnAlias = scannerSettings.AliasNamed(prop);
                    column.IgnoreColumn = scannerSettings.IgnorePropertiesWhere.Any(x => x.Invoke(prop));
                    column.DbColumnType = scannerSettings.DbColumnTypesAs(prop);
                    column.ResultColumn = scannerSettings.ResultPropertiesWhere(prop);
                    column.ComputedColumn = scannerSettings.ComputedPropertiesWhere(prop);
                    column.VersionColumn = scannerSettings.VersionPropertiesWhere(prop);
                    column.VersionColumnType = scannerSettings.VersionColumnTypeAs(prop);
                    column.ForceUtc = scannerSettings.ForceDateTimesToUtcWhere(prop);

                    if (!pocoDefn.ColumnConfiguration.ContainsKey(prop.Name))
                        pocoDefn.ColumnConfiguration.Add(prop.Name, column);
                }

                config.Add(type, pocoDefn);
            }

            MergeOverrides(config, scannerSettings.MappingOverrides);

            //if (scannerSettings.OverrideWithAttributes)
            //{
            //    MergeAttributeOverrides(config);
            //}

            var pocoMappings = new Mappings {Config = config};
            return pocoMappings;
        }
Example #4
0
        private static ConventionScannerSettings ProcessSettings(Action <IConventionScanner> scanner)
        {
            var defaultScannerSettings = new ConventionScannerSettings
            {
                PrimaryKeysAutoIncremented = x => true,
                PrimaryKeysNamed           = x => "ID",
                TablesNamed              = x => x.Name,
                PropertiesNamed          = x => x.Name,
                AliasNamed               = x => null,
                DbColumnTypesAs          = x => null,
                ResultPropertiesWhere    = x => false,
                VersionPropertiesWhere   = x => false,
                VersionColumnTypeAs      = x => VersionColumnType.Number,
                ComputedPropertiesWhere  = x => false,
                ForceDateTimesToUtcWhere = x => true,
                SequencesNamed           = x => null,
                Lazy = false
            };

            scanner.Invoke(new ConventionScanner(defaultScannerSettings));
            return(defaultScannerSettings);
        }
 private static ConventionScannerSettings ProcessSettings(Action<IConventionScanner> scanner)
 {
     var defaultScannerSettings = new ConventionScannerSettings
     {
         PrimaryKeysAutoIncremented = x => true,
         PrimaryKeysNamed = x => "ID",
         TablesNamed = x => x.Name,
         PropertiesNamed = x => x.Name,
         AliasNamed = x => null,
         DbColumnTypesAs = x => null,
         ResultPropertiesWhere = x => false,
         VersionPropertiesWhere = x => false,
         VersionColumnTypeAs = x => VersionColumnType.Number,
         ComputedPropertiesWhere = x => false,
         ForceDateTimesToUtcWhere = x => true,
         SequencesNamed = x => null,
         Lazy = false
     };
     scanner.Invoke(new ConventionScanner(defaultScannerSettings));
     return defaultScannerSettings;
 }
        private static IEnumerable<Type> FindTypes(ConventionScannerSettings scannerSettings)
        {
            if (scannerSettings.TheCallingAssembly)
                scannerSettings.Assemblies.Add(FindTheCallingAssembly());

            var types = scannerSettings.Assemblies
                .SelectMany(x => x.GetExportedTypes())
                .Where(x => scannerSettings.IncludeTypes.All(y => y.Invoke(x)))
                .Where(x => !x.IsNested && !typeof (Map<>).IsAssignableFrom(x) && !typeof (Mappings).IsAssignableFrom(x));
            return types;
        }
 public PropertyBuilderConventions(ConventionScannerSettings scannerSettings)
 {
     _scannerSettings = scannerSettings;
 }
 public ConventionScanner(ConventionScannerSettings scannerSettings)
 {
     _scannerSettings = scannerSettings;
 }
Example #9
0
 public ConventionScanner(ConventionScannerSettings scannerSettings)
 {
     _scannerSettings = scannerSettings;
 }
Example #10
0
 public PropertyBuilderConventions(ConventionScannerSettings scannerSettings)
 {
     _scannerSettings = scannerSettings;
 }