static NPocoDatabase() { factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPocoDatabase("connectionStringName")); x.WithFluentConfig(FluentMappingConfiguration.Configure(new NPocoDatabaseMappings())); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration.GetConnectionString("DefaultConnection"); var dbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(connection, DatabaseType.SqlServer2012, System.Data.SqlClient.SqlClientFactory.Instance)); x.WithFluentConfig(FluentMappingConfiguration.Configure(new NpocoMappings())); }); services.AddSingleton(dbFactory); services.AddControllers(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IVehicleService, VehicleService>(); services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin(); builder.AllowAnyHeader(); builder.AllowAnyMethod(); }); }); // services.AddSwaggerGen(c => // { // c.SwaggerDoc("v1", new Info { Title = "API", Version = "v1" }); // }); }
public DbFactory() { var fluentConfig = FluentMappingConfiguration.Scan(scanner => { scanner.TheCallingAssembly(); scanner.IncludeTypes(x => x.IsClass && !x.IsAbstract && x.Namespace.EndsWith("Models")); scanner.WithSmartConventions(); scanner.PrimaryKeysNamed(m => "Id"); // override primary key name convention from "SmartConventions" scanner.Columns .IgnoreWhere(mi => ColumnInfo.FromMemberInfo(mi).IgnoreColumn) .ResultWhere(mi => ColumnInfo.FromMemberInfo(mi).ResultColumn) .ComputedWhere(mi => ColumnInfo.FromMemberInfo(mi).ComputedColumn) .VersionWhere(mi => ColumnInfo.FromMemberInfo(mi).VersionColumn) .Named(mi => mi.GetCustomAttributes <ColumnAttribute>().Any() ? mi.GetCustomAttribute <ColumnAttribute>().Name : mi.Name) .Aliased(mi => mi.GetCustomAttributes <AliasAttribute>().Any() ? mi.GetCustomAttribute <AliasAttribute>().Alias : null) .DbColumnTypeAs(mi => mi.GetCustomAttributes <ColumnTypeAttribute>().Any() ? mi.GetCustomAttribute <ColumnTypeAttribute>().Type : null); }); var connString = ConfigurationManager.ConnectionStrings["test"].ConnectionString; factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(connString, databaseType)); x.WithFluentConfig(fluentConfig); }); }
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.Columns.IgnoreWhere(x => x.GetCustomAttributes <IgnoreAttribute>().Any()); s.PrimaryKeysNamed(t => Inflector.AddUnderscores(t.Name).ToLower() + "_id"); s.PrimaryKeysAutoIncremented(t => true); } }); Config = fluentConfig; } catch (ReflectionTypeLoadException) { //Swallow } }
public void FluentMappingForPrivates() { var map = FluentMappingConfiguration.Configure(new FluentMappingOverridesForPrivates()); var pd = map.Config(new MapperCollection()).Resolver(typeof(NewMapperTests.Result36), new PocoDataFactory(new MapperCollection())).Build(); Assert.AreEqual(true, pd.Columns.ContainsKey("Data")); }
private IDatabase CreateDatabaseInstance(IHostingEnvironment env) { Database database; if (env.IsDevelopment()) { var s = new SqliteIntegration(); s.EnsureSharedConnectionConfigured(); database = s.CreateDatabase(); s.RecreateSchema(); } else { database = new Database("Server=localhost;Database=npoco;Trusted_Connection=True;", DatabaseType.SqlServer2012, SqlClientFactory.Instance); } var dbFactory = DatabaseFactory.Config(x => { var fluentConfig = FluentMappingConfiguration.Configure(new NPocoLabMappings()); x.UsingDatabase(() => database); x.WithFluentConfig(fluentConfig); }); return(dbFactory.GetDatabase()); }
public void SetUp() { var types = new[] { typeof(User), typeof(ExtraUserInfo), typeof(Usersss), typeof(House), typeof(Supervisor) }; var dbFactory = new DatabaseFactory(); dbFactory.Config().WithFluentConfig( FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(User).Assembly); s.IncludeTypes(types.Contains); s.WithSmartConventions(); s.Columns.ResultWhere(y => ColumnInfo.FromMemberInfo(y).IgnoreColumn); s.OverrideMappingsWith(new FluentMappingOverrides()); }) ); var testDBType = Convert.ToInt32(ConfigurationManager.AppSettings["TestDBType"]); switch (testDBType) { case 1: // SQLite In-Memory TestDatabase = new InMemoryDatabase(); Database = dbFactory.Build(new Database(TestDatabase.Connection)); break; case 2: // SQL Local DB case 3: // SQL Server TestDatabase = new SQLLocalDatabase(); Database = dbFactory.Build(new Database(TestDatabase.Connection, new SqlServer2008DatabaseType() { UseOutputClause = true })); break; case 4: // SQL CE case 5: // MySQL case 6: // Oracle case 7: // Postgres Assert.Fail("Database platform not supported for unit testing"); return; case 8: // Firebird TestDatabase = new FirebirdDatabase(); var db = new Database(TestDatabase.Connection, new FirebirdDatabaseType()); db.Mapper = new FirebirdDefaultMapper(); Database = dbFactory.Build(db); break; default: Assert.Fail("Unknown database platform specified"); return; } InsertData(); }
/// <summary> /// /// </summary> public static void Setup() { var fluentConfig = FluentMappingConfiguration.Configure(new SqliteMappings()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPoco.Database("conndb", NPoco.DatabaseType.SQLite)); x.WithFluentConfig(fluentConfig); }); }
/// <summary> /// Задать зависимости проекта .Data. /// </summary> /// <param name="kernel">Ядро IoC.</param> private static void ConfigureDataServices(IKernel kernel) { FluentMappingConfiguration.ConfigureMapping(); kernel.Bind <IUnitOfWorkFactory>().To <UnitOfWorkFactory>().InTransientScope(); kernel.Bind <IUserRepository>().To <UserRepository>().InTransientScope(); kernel.Bind <IPlanRepository>().To <PlanRepository>().InTransientScope(); kernel.Bind <IEducationalWorkTypeRepository>().To <EducationalWorkTypeRepository>().InTransientScope(); kernel.Bind <IEducationalWorkRepository>().To <EducationalWorkRepository>().InTransientScope(); }
public static void Setup() { var config = FluentMappingConfiguration.Configure(new CustomMappings()); DatabaseFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new MemeDatabase("MemeLordDb")); x.WithFluentConfig(config); }); }
public static void Setup(IConfiguration configuration) { var fluentConfig = FluentMappingConfiguration.Configure(new LunchMapping(), new AttendeeMapping()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(configuration.GetConnectionString("LocsDatabase"), DatabaseType.SqlServer2012, SqlClientFactory.Instance)); x.WithFluentConfig(fluentConfig); }); }
public void Setup() { var config = FluentMappingConfiguration.Configure(new ServerDomainDBMapping()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(this.connectionString, DatabaseType.SQLite)); x.WithFluentConfig(config); }); }
/// <summary> /// /// </summary> public static void Setup(string config) { var fluentConfig = FluentMappingConfiguration.Configure(new ReviewsServiceMappings()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPoco.Database(config, DatabaseType.SqlServer2012, SqlClientFactory.Instance)); x.WithFluentConfig(fluentConfig); }); }
/// <summary> /// /// </summary> public static void Setup(string config) { //NpgsqlConnection connection = new NpgsqlConnection(config); var fluentConfig = FluentMappingConfiguration.Configure(new OTPSolutionMappings()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPoco.Database(config, DatabaseType.SqlServer2012, SqlClientFactory.Instance)); x.WithFluentConfig(fluentConfig); }); }
public void Setup() { var dbfactory = new DatabaseFactory(); dbfactory .Config() .UsingDatabase(() => new Database("")) .WithFluentConfig(FluentMappingConfiguration.Configure(new MyMappings())); _database = dbfactory.GetDatabase(); }
public static void Setup() { FluentConfig fluentConfig = FluentMappingConfiguration.Configure(new EmployeeMapping()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new SqlServerDatabase(AppSettings.StringConnection)); x.WithFluentConfig(fluentConfig); x.WithMapper(new Mapper()); }); }
public static void Setup(Mappings MappingClass) { var fluentConfig = FluentMappingConfiguration.Configure(MappingClass); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database("CommandsDb")); x.WithFluentConfig(fluentConfig); //x.WithMapper(new Mapper()); }); }
public void Setup() { var dbfactory = new DatabaseFactory(); dbfactory .Config() .UsingDatabase(() => new Database("", new SqlServer2012DatabaseType(), SqlClientFactory.Instance)) .WithFluentConfig(FluentMappingConfiguration.Configure(new MyMappings())); _database = dbfactory.GetDatabase(); }
public DatabaseFactory(IConnectionStringProvider connectionStringProvider, IMappingProvider mappingProvider) { DatabaseFactoryConfigOptions options = new DatabaseFactoryConfigOptions(); var connectionString = connectionStringProvider.GetConnectionString(); var mappings = mappingProvider.GetMappings(); options.Database = () => new LoggingDatabase(connectionString); options.PocoDataFactory = FluentMappingConfiguration.Configure(mappings); databaseFactory = new NPoco.DatabaseFactory(options); }
public static void Init() { DbFact = new DatabaseFactory(); var config = FluentMappingConfiguration.Scan(x => { x.TheCallingAssembly(); x.WithSmartConventions(true); x.Columns.IgnoreWhere(y => y.GetCustomAttributes(typeof(IgnoreAttribute), true).Any()); x.OverrideMappingsWith(new OverrideNPoco()); }); DbFact.Config().WithFluentConfig(config); }
public static void Initialize() { var fluentConfig = FluentMappingConfiguration.Configure ( // new CostumeMapping() ); DbFactory = DatabaseFactory.Config(x => { x.WithFluentConfig(fluentConfig); x.WithInterceptor(new NPocoDbInterceptors()); }); }
public void FluentMappingForPrivatesScan() { var map = FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(NewMapperTests.Result36).GetTypeInfo().Assembly); s.IncludeTypes(t => t == typeof(NewMapperTests.Result36)); s.OverrideMappingsWith(new FluentMappingOverridesForPrivatesScan()); }); var pd = map.Config(new MapperCollection()).Resolver(typeof(NewMapperTests.Result36), new PocoDataFactory(new MapperCollection())).Build(); Assert.AreEqual(true, pd.Columns.ContainsKey("Data")); Assert.AreEqual(true, pd.Columns.ContainsKey("Data1")); }
public Database CreateDatabase() { var fluentConfig = FluentMappingConfiguration.Configure(new NPocoLabMappings()); var dbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(Connection, DatabaseType.SQLite)); x.WithFluentConfig(fluentConfig); }); return(dbFactory.GetDatabase()); }
public void ScanIgnoresColumnsDefinedByConvention() { var map = FluentMappingConfiguration.Scan(scan => { scan.Assembly(this.GetType().Assembly); scan.IncludeTypes(x => x == typeof(User)); scan.Columns.IgnoreWhere(x => x.Name == "Age"); }); var pd = map.Config(new Mapper()).Resolver(typeof(User)); Assert.False(pd.Columns.ContainsKey("Age")); }
public static void Initialize() { var fluentConfig = FluentMappingConfiguration.Configure ( new CustomerMapping() ); DbFactory = DatabaseFactory.Config(x => { x.WithFluentConfig(fluentConfig); x.WithInterceptor(new DataServiceInterceptors()); }); }
public void ScanIgnoresColumnsDefinedByConvention() { var map = FluentMappingConfiguration.Scan(scan => { scan.Assembly(this.GetType().GetTypeInfo().Assembly); scan.IncludeTypes(x => x == typeof(User) || ReflectionUtils.GetFieldsAndPropertiesForClasses(typeof(User)).Select(y => y.GetMemberInfoType()).Contains(x)); scan.Columns.IgnoreWhere(x => x.Name == "Age"); }); var pd = map.Config(new MapperCollection()).Resolver(typeof(User), new PocoDataFactory(new MapperCollection())).Build(); Assert.False(pd.Columns.ContainsKey("Age")); }
public void FluentMappingOverridesShouldOverrideComplexMappingPrefix() { var map = FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(User).GetTypeInfo().Assembly); s.IncludeTypes(t => t == typeof(User)); s.Columns.ComplexPropertiesWhere(y => ColumnInfo.FromMemberInfo(y).ComplexMapping); s.OverrideMappingsWith(new FluentMappingOverrides()); }); var pd = map.Config(new MapperCollection()).Resolver(typeof(User), new PocoDataFactory(new MapperCollection())).Build(); Assert.AreEqual(true, pd.Columns.ContainsKey("CM__Street")); }
public void PrimaryKeyShouldGetRemapped() { var map = FluentMappingConfiguration.Scan(scan => { scan.Assembly(this.GetType().GetTypeInfo().Assembly); scan.IncludeTypes(x => x == typeof(User) || ReflectionUtils.GetFieldsAndPropertiesForClasses(typeof(User)).Select(y => y.GetMemberInfoType()).Contains(x)); scan.OverrideMappingsWith(new MyPKMappings()); }); var pd = map.Config(new MapperCollection()).Resolver(typeof(User), new PocoDataFactory(new MapperCollection())).Build(); Assert.True(pd.Columns.ContainsKey("user_id")); Assert.AreEqual("user_id", pd.TableInfo.PrimaryKey); }
public void ScanSetsResultColumnsDefinedByConvention() { var map = FluentMappingConfiguration.Scan(scan => { scan.Assembly(this.GetType().Assembly); scan.IncludeTypes(x => x == typeof(User)); scan.Columns.ResultWhere(x => x.Name == "Age"); }); var pd = map.Config(new Mapper()).Resolver(typeof(User), Cache <string, Type> .CreateStaticCache()); Assert.True(pd.Columns.ContainsKey("Age")); Assert.True(pd.Columns["Age"].ResultColumn); }
public void ScanSetsNameOfColumnDefinedByConvention() { var map = FluentMappingConfiguration.Scan(scan => { scan.Assembly(this.GetType().Assembly); scan.IncludeTypes(x => x == typeof(User)); scan.Columns.Named(x => x.Name + "000"); }); var pd = map.Config(new Mapper()).Resolver(typeof(User)); Assert.True(pd.Columns.ContainsKey("Age000")); Assert.AreEqual("Age", pd.Columns["Age000"].MemberInfo.Name); }