Exemplo n.º 1
0
        public static void Setup(Type type)
        {
            try
            {
                var items = AppDomain.CurrentDomain.GetAssemblies()
                    .SelectMany(s => s.GetTypes())
                    .Where(type.IsAssignableFrom).Select(t => t.Assembly);

                var fluentConfig = FluentMappingConfiguration.Scan(s =>
                {
                    foreach (var item in items)
                    {
                        s.Assembly(item);
                        s.WithSmartConventions();
                        s.TablesNamed(
                            t =>
                                t.GetCustomAttributes(true).OfType<TableNameAttribute>().FirstOrDefault()?.Value ??
                                Inflector.AddUnderscores(Inflector.MakePlural(t.Name)).ToLower());
                        s.Columns.Named(m => Inflector.AddUnderscores(m.Name).ToLower());
                        s.PrimaryKeysNamed(t => Inflector.AddUnderscores(t.Name).ToLower() + "_id");
                        s.PrimaryKeysAutoIncremented(t => true);
                    }
                });

                Config = fluentConfig;
            }
            catch (ReflectionTypeLoadException)
            {
            }
        }
Exemplo n.º 2
0
 public DatabaseFactoryConfig WithFluentConfig(FluentConfig fluentConfig)
 {
     _options.PocoDataFactory = fluentConfig;
     return this;
 }