/// <summary> /// /// </summary> public static void Setup() { DbFactory = DatabaseFactory.Config(x => { //x.UsingDatabase(() => new NPoco.Database(new )); }); }
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); }); }
static NPocoDatabase() { factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPocoDatabase("connectionStringName")); x.WithFluentConfig(FluentMappingConfiguration.Configure(new NPocoDatabaseMappings())); }); }
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()); }
// 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 static void Init() { _DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new NPocoDataBase(_defaultConnectionName)); }); }
public static DatabaseFactory Get(string connectionString) { return(DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(connectionString, ProviderName)); x.WithFluentConfig(Config); })); }
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(); }
public void Setup() { var dbfactory = new DatabaseFactory(); dbfactory .Config() .UsingDatabase(() => new Database("")) .WithFluentConfig(FluentMappingConfiguration.Configure(new MyMappings())); _database = dbfactory.GetDatabase(); }
/// <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> /// /// </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); }); }
public void Setup() { var config = FluentMappingConfiguration.Configure(new ServerDomainDBMapping()); DbFactory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(this.connectionString, DatabaseType.SQLite)); 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 static DatabaseFactory InitializeFactory(string connectionString) { string connection = ConfigurationManager.ConnectionStrings["ConnectionStringDEBUG"].ConnectionString; string provider = ConfigurationManager.ConnectionStrings["ConnectionStringDEBUG"].ProviderName; return(DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(connection, provider)); })); }
public void DatabaseShouldbeReturnedWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); }); Assert.AreEqual(db, factory.GetDatabase()); }
public void Setup() { var dbfactory = new DatabaseFactory(); dbfactory .Config() .UsingDatabase(() => new Database("")) .WithFluentConfig(FluentMappingConfiguration.Configure(new MyMappings())); _database = dbfactory.GetDatabase(); }
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()); }); }
/// <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 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 void Setup() { var dbfactory = new DatabaseFactory(); dbfactory .Config() .UsingDatabase(() => new Database("", new SqlServer2012DatabaseType(), SqlClientFactory.Instance)) .WithFluentConfig(FluentMappingConfiguration.Configure(new MyMappings())); _database = dbfactory.GetDatabase(); }
public void MapperShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var mapper = new Mapper(); var factory = DatabaseFactory.Config(x => { x.WithMapper(mapper); }); Assert.AreEqual(mapper, factory.Build(db).Mapper); }
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 MapperShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfigWhenCallingGetDatabase() { var db = new Database(new SqlConnection()); var mapper = new Mapper(); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); x.WithMapper(mapper); }); Assert.AreEqual(mapper, factory.GetDatabase().Mapper); }
public void MapperShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfigWhenCallingGetDatabase() { var db = new Database(new SqlConnection()); var mapper = new Mapper(); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); var databaseFactoryConfig = x.WithMapper(mapper); }); Assert.True(factory.Build(db).Mappers.Contains(mapper)); }
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 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())); 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(); }
public void FluentConfigShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var fluentConfig = new FluentConfig(x => y => new PocoData(y, new Mapper())); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); x.WithFluentConfig(fluentConfig); }); var database = factory.GetDatabase(); Assert.AreEqual(fluentConfig.Config(null), database.PocoDataFactory); }
/// <summary> /// Initializes the configuration and sets the <see cref="Factory"/> property. /// </summary> /// <remarks>Adapted from https://github.com/schotime/NPoco/wiki/Fluent-Mappings-including-Conventional /// </remarks> public static void Setup(IDatabaseConfigurationSettings databaseConfigurationSettings) { var fluentConfig = FluentMappingConfiguration.Configure(new IMap[] { new LocationInformationMapping(), new PropertyEnquiryMapping(), new PropertyInformationMapping(), new PropertyPhotoMapping() }); Factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(databaseConfigurationSettings.ConnectionStringName)); x.WithFluentConfig(fluentConfig); }); }
public void FluentConfigShouldBePlacedOnDatabaseWhenInsertedIntoFactoryConfig() { var db = new Database(new SqlConnection()); var mapperCollection = new MapperCollection(); var pocoDataFactory = new FluentPocoDataFactory((y, f) => new PocoDataBuilder(y, mapperCollection).Init(), mapperCollection); var fluentConfig = new FluentConfig(x => pocoDataFactory); var factory = DatabaseFactory.Config(x => { x.UsingDatabase(() => db); x.WithFluentConfig(fluentConfig); }); var database = factory.GetDatabase(); Assert.AreEqual(fluentConfig.Config(null), database.PocoDataFactory); }
public void ValueObjectTestGetWithoutInterface() { var map = FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(User2).GetTypeInfo().Assembly); s.IncludeTypes(t => t == typeof(User2)); s.Columns.ValueObjectColumnWhere(y => y.GetMemberInfoType() == typeof(MyNameObject2)); }); var factory = DatabaseFactory.Config(x => { x.WithFluentConfig(map); }); var s1 = factory.Build(Database).Single <User2>("select 'testtext' as Name /*poco_dual*/"); Assert.AreEqual("testtext", s1.Name.MyAwesomeValue); }
public void SetUp() { var types = new[] { typeof(User), typeof(ExtraUserInfo) }; var dbFactory = new DatabaseFactory(); dbFactory.Config().WithFluentConfig( FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(User).Assembly); s.IncludeTypes(types.Contains); s.WithSmartConventions(); 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())); break; case 4: case 5: case 6: Assert.Fail("Database platform not supported for unit testing"); return; default: Assert.Fail("Unknown database platform specified"); return; } InsertData(); }
public void DifferentFactoriesWithDifferentMappingsGetDifferentPocoDataForSamePocoWithoutFactory() { // Assume these factories connect to different data sources var db1 = new Database(new SqlConnection()) { PocoDataFactory = new PocoDataFactory(new MapperCollection()) }; var factory2 = DatabaseFactory.Config(x => { x.UsingDatabase(() => new Database(new SqlConnection())); x.WithFluentConfig(FluentMappingConfiguration.Configure(new AnotherMapping())); }); var pocoData1 = db1.PocoDataFactory.ForType(typeof(WanderingPoco)); var pocoData2 = factory2.GetDatabase().PocoDataFactory.ForType(typeof(WanderingPoco)); Assert.AreEqual("Table1", pocoData1.TableInfo.TableName); Assert.AreEqual("Table2", pocoData2.TableInfo.TableName); }
public void SetUp() { var types = new[] { typeof(User), typeof(ExtraUserInfo) }; var dbFactory = new DatabaseFactory(); dbFactory.Config().WithFluentConfig( FluentMappingConfiguration.Scan(s => { s.Assembly(typeof (User).Assembly); s.IncludeTypes(types.Contains); s.WithSmartConventions(); 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 SqlServer2012DatabaseType())); break; case 4: case 5: case 6: Assert.Fail("Database platform not supported for unit testing"); return; default: Assert.Fail("Unknown database platform specified"); return; } InsertData(); }
public void SetUp() { var types = new[] { typeof(User), typeof(ExtraUserInfo), typeof(UserWithExtraInfo), typeof(Usersss), typeof(House), typeof(Supervisor) }; var dbFactory = new DatabaseFactory(); var config = FluentMappingConfiguration.Scan(s => { s.Assembly(typeof(User).GetTypeInfo().Assembly); s.IncludeTypes(types.Contains); s.PrimaryKeysNamed(y => ToLowerIf(y.Name + "Id", false)); s.TablesNamed(y => ToLowerIf(Inflector.MakePlural(y.Name), false)); s.Columns.Named(x => ToLowerIf(x.Name, false)); s.Columns.ForceDateTimesToUtcWhere(x => x.GetMemberInfoType() == typeof(DateTime) || x.GetMemberInfoType() == typeof(DateTime?)); s.Columns.ResultWhere(y => ColumnInfo.FromMemberInfo(y).ResultColumn); s.OverrideMappingsWith(new FluentMappingOverrides()); s.OverrideMappingsWith(new OneToManyMappings()); }); dbFactory.Config().WithFluentConfig(config); var configuration = new ConfigurationBuilder() .AddJsonFile("config.json") .Build(); var testDBType = Convert.ToInt32(configuration.GetSection("TestDBType").Value); 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 var dataSource = configuration.GetSection("TestDbDataSource").Value; TestDatabase = new SQLLocalDatabase(dataSource); Database = dbFactory.Build(new Database(TestDatabase.Connection, new SqlServer2008DatabaseType())); break; case 4: // SQL CE case 5: // MySQL case 6: // Oracle case 7: // Postgres Assert.Fail("Database platform not supported for unit testing"); return; #if !DNXCORE50 case 8: // Firebird TestDatabase = new FirebirdDatabase(); var db = new Database(TestDatabase.Connection, new FirebirdDatabaseType()); db.Mappers.Insert(0, new FirebirdDefaultMapper()); Database = dbFactory.Build(db); break; #endif default: Assert.Fail("Unknown database platform specified"); return; } InsertData(); }