public void Transaction_commits_inserts_to_different_tables() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.CreateTable <ModelWithFieldsOfDifferentTypes>(true); db.CreateTable <ModelWithOnlyStringFields>(true); db.DeleteAll <ModelWithIdAndName>(); db.Insert(new ModelWithIdAndName(0)); using (var dbTrans = db.BeginTransaction()) { db.Insert(new ModelWithIdAndName(0)); db.Insert(ModelWithFieldsOfDifferentTypes.Create(3)); db.Insert(ModelWithOnlyStringFields.Create("id3")); Assert.That(db.Select <ModelWithIdAndName>(), Has.Count.EqualTo(2)); Assert.That(db.Select <ModelWithFieldsOfDifferentTypes>(), Has.Count.EqualTo(1)); Assert.That(db.Select <ModelWithOnlyStringFields>(), Has.Count.EqualTo(1)); dbTrans.Commit(); } Assert.That(db.Select <ModelWithIdAndName>(), Has.Count.EqualTo(2)); Assert.That(db.Select <ModelWithFieldsOfDifferentTypes>(), Has.Count.EqualTo(1)); Assert.That(db.Select <ModelWithOnlyStringFields>(), Has.Count.EqualTo(1)); } }
public void Transaction_rollsback_transactions_to_different_tables() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdAndName>(true); db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); db.CreateTable<ModelWithOnlyStringFields>(true); db.DeleteAll<ModelWithIdAndName>(); db.Insert(new ModelWithIdAndName(0)); using (var dbTrans = db.BeginTransaction()) { db.Insert(new ModelWithIdAndName(0)); db.Insert(ModelWithFieldsOfDifferentTypes.Create(3)); db.Insert(ModelWithOnlyStringFields.Create("id3")); Assert.That(db.Select<ModelWithIdAndName>(), Has.Count.EqualTo(2)); Assert.That(db.Select<ModelWithFieldsOfDifferentTypes>(), Has.Count.EqualTo(1)); Assert.That(db.Select<ModelWithOnlyStringFields>(), Has.Count.EqualTo(1)); } Assert.That(db.Select<ModelWithIdAndName>(), Has.Count.EqualTo(1)); Assert.That(db.Select<ModelWithFieldsOfDifferentTypes>(), Has.Count.EqualTo(0)); Assert.That(db.Select<ModelWithOnlyStringFields>(), Has.Count.EqualTo(0)); } }
public void Can_overwrite_ModelWithIdOnly_table() { using var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open(); db.CreateTable <ModelWithIdOnly>(true); db.Insert(new ModelWithIdOnly(1)); db.Insert(new ModelWithIdOnly(2)); db.CreateTable <ModelWithIdOnly>(true); var rows = db.Select <ModelWithIdOnly>(); Assert.That(rows, Has.Count.EqualTo(0)); }
public void Can_preserve_ModelWithIdAndName_table() { using var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open(); db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); db.Insert(new ModelWithIdAndName(0)); db.Insert(new ModelWithIdAndName(0)); db.CreateTable <ModelWithIdAndName>(false); var rows = db.Select <ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(2)); }
public void Can_create_table_containing_DateTime_column() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <Analyze>(true); } }
public void Can_get_data_from_TableWithNamigStrategy_with_query_by_example() { OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new PrefixNamingStrategy { TablePrefix = "tab_", ColumnPrefix = "col_", }; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id = "998", AlbumId = "112", AlbumName = "ElectroShip", Name = "QueryByExample" }; db.Save <ModelWithOnlyStringFields>(m); var modelFromDb = db.Where <ModelWithOnlyStringFields>(new { Name = "QueryByExample" })[0]; Assert.AreEqual(m.Name, modelFromDb.Name); } OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase(); }
public void CanCreateSimpleForeignKey() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <TypeWithSimpleForeignKey>(true); } }
public void Can_insert_table_with_blobs() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { var hold = OrmLiteConfig.DialectProvider.GetStringConverter().StringLength; OrmLiteConfig.DialectProvider.GetStringConverter().StringLength = 1024; db.CreateTable <OrderBlob>(true); OrmLiteConfig.DialectProvider.GetStringConverter().StringLength = hold; var row = OrderBlob.Create(1); db.Insert(row); var rows = db.Select <OrderBlob>(); Assert.That(rows, Has.Count.EqualTo(1)); var newRow = rows[0]; Assert.That(newRow.Id, Is.EqualTo(row.Id)); Assert.That(newRow.Customer.Id, Is.EqualTo(row.Customer.Id)); Assert.That(newRow.Employee.Id, Is.EqualTo(row.Employee.Id)); Assert.That(newRow.IntIds, Is.EquivalentTo(row.IntIds)); Assert.That(newRow.CharMap, Is.EquivalentTo(row.CharMap)); Assert.That(newRow.OrderDetails.Count, Is.EqualTo(row.OrderDetails.Count)); Assert.That(newRow.OrderDetails[0].ProductId, Is.EqualTo(row.OrderDetails[0].ProductId)); Assert.That(newRow.OrderDetails[1].ProductId, Is.EqualTo(row.OrderDetails[1].ProductId)); Assert.That(newRow.OrderDetails[2].ProductId, Is.EqualTo(row.OrderDetails[2].ProductId)); } }
public void Can_query_using_float_in_alernate_culuture() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <Point>(true); db.Insert(new Point { Width = 4, Height = 1.123f, Top = 3.456d, Left = 2.345m }); var points = db.Select <Point>(); Console.WriteLine(points.Dump()); Assert.That(points[0].Width, Is.EqualTo(4)); Assert.That(points[0].Height, Is.EqualTo(1.123f)); Assert.That(points[0].Top, Is.EqualTo(3.456d)); Assert.That(points[0].Left, Is.EqualTo(2.345m)); // returns no rows! FirebirdSql bug? points = db.Select <Point>("Height=@height", new { height = 1.123f }); Assert.That(points.Count > 0); } }
public void Setup() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ReferencedType>(true); } }
public void Setup() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ReferencedType>(true); } }
public void Can_create_ModelWithIdOnly_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdOnly>(true); } }
public void CanCreateForeignWithOnDeleteSetNull() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <TypeWithOnDeleteSetNull>(true); } }
public void Can_create_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); } }
public void Can_Select_In_for_string_value() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); for (int i = 1; i <= n; i++) { ModelWithIdAndName m = new ModelWithIdAndName() { Name = "Name" + i.ToString() }; db.Insert(m); } var selectInNames = new[] { "Name1", "Name2" }; var rows = db.Select <ModelWithIdAndName>("Name IN ({0})".Fmt(selectInNames.SqlInParams()), new { values = selectInNames.SqlInValues() }); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); rows = db.Select <ModelWithIdAndName>("Name IN (@p1, @p2)", new { p1 = "Name1", p2 = "Name2" }); Assert.That(rows.Count, Is.EqualTo(selectInNames.Length)); } }
public void Can_create_ModelWithIdOnly_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdOnly>(true); } }
public void Can_loop_each_with_filter_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); var rowIds = new List <string>(new[] { "id-1", "id-2", "id-3" }); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var filterRow = ModelWithOnlyStringFields.Create("id-4"); filterRow.AlbumName = "FilteredName"; db.Insert(filterRow); var dbRowIds = new List <string>(); var rows = db.WhereLazy <ModelWithOnlyStringFields>(new { filterRow.AlbumName }); foreach (var row in rows) { dbRowIds.Add(row.Id); } Assert.That(dbRowIds, Has.Count.EqualTo(1)); Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id)); } }
public void Can_create_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithFieldsOfDifferentTypes>(true); } }
public void Can_get_data_from_TableWithNamigStrategy_with_query_by_example() { OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new PrefixNamingStrategy { TablePrefix = "tab_", ColumnPrefix = "col_", }; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id = "998", AlbumId = "112", AlbumName = "ElectroShip", Name = "QueryByExample" }; db.Save<ModelWithOnlyStringFields>(m); var modelFromDb = db.Where<ModelWithOnlyStringFields>(new {Name = "QueryByExample"})[0]; Assert.AreEqual(m.Name, modelFromDb.Name); } OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase(); }
public void Can_preserve_ModelWithIdOnly_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdOnly>(true); db.Insert(new ModelWithIdOnly(1)); db.Insert(new ModelWithIdOnly(2)); db.CreateTable<ModelWithIdOnly>(false); var rows = db.Select<ModelWithIdOnly>(); Assert.That(rows, Has.Count.EqualTo(2)); } }
public void CanCreateSimpleForeignKey() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<TypeWithSimpleForeignKey>(true); } }
public void CanCreateForeignWithOnDeleteNoAction() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<TypeWithOnDeleteNoAction>(true); } }
public void Can_get_data_from_TableWithNamigStrategy_AfterChangingNamingStrategy() { using (new TemporaryNamingStrategy(new PrefixNamingStrategy { TablePrefix = "tab_", ColumnPrefix = "col_" })) using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id = "998", AlbumId = "112", AlbumName = "ElectroShip", Name = "QueryByExample" }; db.Save <ModelWithOnlyStringFields>(m); var modelFromDb = db.Where <ModelWithOnlyStringFields>(new { Name = "QueryByExample" })[0]; Assert.AreEqual(m.Name, modelFromDb.Name); modelFromDb = db.SingleById <ModelWithOnlyStringFields>("998"); Assert.AreEqual(m.Name, modelFromDb.Name); } using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id = "998", AlbumId = "112", AlbumName = "ElectroShip", Name = "QueryByExample" }; db.Save <ModelWithOnlyStringFields>(m); var modelFromDb = db.Where <ModelWithOnlyStringFields>(new { Name = "QueryByExample" })[0]; Assert.AreEqual(m.Name, modelFromDb.Name); modelFromDb = db.SingleById <ModelWithOnlyStringFields>("998"); Assert.AreEqual(m.Name, modelFromDb.Name); } using (new TemporaryNamingStrategy(new PrefixNamingStrategy { TablePrefix = "tab_", ColumnPrefix = "col_" })) using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id = "998", AlbumId = "112", AlbumName = "ElectroShip", Name = "QueryByExample" }; db.Save <ModelWithOnlyStringFields>(m); var modelFromDb = db.Where <ModelWithOnlyStringFields>(new { Name = "QueryByExample" })[0]; Assert.AreEqual(m.Name, modelFromDb.Name); modelFromDb = db.SingleById <ModelWithOnlyStringFields>("998"); Assert.AreEqual(m.Name, modelFromDb.Name); } }
public void Can_create_TableWithNamigStrategy_table_nameUnderscoreCoumpound() { using (new TemporaryNamingStrategy(new UnderscoreSeparatedCompoundNamingStrategy())) using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); } }
public void Can_create_TableWithNamigStrategy_table_nameUnderscoreCoumpound() { using (new TemporaryNamingStrategy(new UnderscoreSeparatedCompoundNamingStrategy())) using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); } }
public void Can_insert_into_ModelWithComplexTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithComplexTypes>(true); var row = ModelWithComplexTypes.Create(1); db.Insert(row); } }
public void Can_insert_into_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var row = ModelWithFieldsOfDifferentTypes.Create(1); db.Insert(row); } }
public void Can_create_ModelWithCompositeIndexFields_table() { OrmLiteConfig.DialectProvider.DefaultStringLength=128; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithCompositeIndexFields>(true); var sql = OrmLiteConfig.DialectProvider.ToCreateIndexStatements(typeof(ModelWithCompositeIndexFields)).Join(); Assert.IsTrue(sql.Contains("idx_modelwcif_name")); Assert.IsTrue(sql.Contains("idx_modelwcif_comp1_comp2")); } }
public void Can_create_ModelWithCompositeIndexFields_table() { OrmLiteConfig.DialectProvider.GetStringConverter().StringLength = 128; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithCompositeIndexFields>(true); var sql = OrmLiteConfig.DialectProvider.ToCreateIndexStatements(typeof(ModelWithCompositeIndexFields)).Join(); Assert.IsTrue(sql.Contains("idx_modelwcif_name")); Assert.IsTrue(sql.Contains("idx_modelwcif_comp1_comp2")); } }
public void Can_get_data_from_TableWithNamigStrategy_with_GetById() { using (new TemporaryNamingStrategy(new PrefixNamingStrategy { TablePrefix = "tab_", ColumnPrefix = "col_" })) using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); ModelWithOnlyStringFields m = new ModelWithOnlyStringFields() { Id= "999", AlbumId = "112", AlbumName="ElectroShip", Name = "MyNameIsBatman"}; db.Save<ModelWithOnlyStringFields>(m); var modelFromDb = db.SingleById<ModelWithOnlyStringFields>("999"); Assert.AreEqual(m.Name, modelFromDb.Name); } }
public void Does_table_Exists() { using var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open(); db.DropTable <ModelWithIdOnly>(); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, nameof(ModelWithIdOnly)), Is.False); db.CreateTable <ModelWithIdOnly>(true); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, nameof(ModelWithIdOnly)), Is.True); }
public void Can_insert_and_select_from_OrderLineData() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<SampleOrderLine>(true); var orderIds = new[] { 1, 2, 3, 4, 5 }.ToList(); orderIds.ForEach(x => db.Insert( SampleOrderLine.Create(Guid.NewGuid(), x, 1))); var rows = db.Select<SampleOrderLine>(); Assert.That(rows, Has.Count.EqualTo(orderIds.Count)); } }
public void Can_GetById_string_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); var rowIds = new List<string>(new[] {"id-1", "id-2", "id-3"}); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var row = db.GetById<ModelWithOnlyStringFields>("id-1"); Assert.That(row.Id, Is.EqualTo("id-1")); } }
public void Can_GetById_int_from_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var rowIds = new List<int>(new[] {1, 2, 3}); rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x))); var row = db.GetById<ModelWithFieldsOfDifferentTypes>(1); Assert.That(row.Id, Is.EqualTo(1)); } }
public void Can_store_DateTime_Value() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <Analyze>(true); var obj = new Analyze { Id = 1, Date = DateTime.Now, Url = "http://www.google.com" }; db.Save(obj); } }
public void Can_GetById_int_from_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithFieldsOfDifferentTypes>(true); var rowIds = new List <int>(new[] { 1, 2, 3 }); rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x))); var row = db.SingleById <ModelWithFieldsOfDifferentTypes>(1); Assert.That(row.Id, Is.EqualTo(1)); } }
public void Can_insert_and_select_from_OrderLineData() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <SampleOrderLine>(true); var orderIds = new[] { 1, 2, 3, 4, 5 }.ToList(); orderIds.ForEach(x => db.Insert( SampleOrderLine.Create(Guid.NewGuid(), x, 1))); var rows = db.Select <SampleOrderLine>(); Assert.That(rows, Has.Count.EqualTo(orderIds.Count)); } }
public void Can_GetById_string_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); var rowIds = new List <string>(new[] { "id-1", "id-2", "id-3" }); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var row = db.SingleById <ModelWithOnlyStringFields>("id-1"); Assert.That(row.Id, Is.EqualTo("id-1")); } }
public void Can_create_ModelWithAutoId_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, Firebird4Dialect.Provider).OpenDbConnection()) { db.CreateTable <ModelWithAutoId>(true); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, nameof(ModelWithAutoId)), Is.True); db.DropTable <ModelWithAutoId>(); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, nameof(ModelWithAutoId)), Is.False); } }
public void Can_select_scalar_value() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(0))); var count = db.Scalar <int>("SELECT COUNT(*) FROM ModelWIN"); Assert.That(count, Is.EqualTo(n)); } }
public void Can_SaveAll_and_select_from_ModelWithFieldsOfDifferentTypes_table_with_no_ids() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); db.DeleteAll<ModelWithFieldsOfDifferentTypes>(); var rowIds = new List<int> {1, 2, 3, 4, 5}; var newRows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(default(int))); db.SaveAll(newRows); var rows = db.Select<ModelWithFieldsOfDifferentTypes>(); Assert.That(rows, Has.Count.EqualTo(newRows.Count)); } }
public void Can_GetByIds_int_from_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithFieldsOfDifferentTypes>(true); var rowIds = new List <int>(new[] { 1, 2, 3 }); rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x))); var rows = db.SelectByIds <ModelWithFieldsOfDifferentTypes>(rowIds); var dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Is.EquivalentTo(rowIds)); } }
public void Check_AutoId_generation() { using (var db = new OrmLiteConnectionFactory(ConnectionString, Firebird4Dialect.Provider).OpenDbConnection()) { db.CreateTable <ModelWithAutoId>(true); db.Insert(new ModelWithAutoId { Name = "Isaac Newton" }); db.Insert(new ModelWithAutoId { Name = "Alan Kay" }); var rows = db.Select <ModelWithAutoId>(); Assert.That(rows, Has.Count.EqualTo(2)); } }
public void Can_GetByIds_string_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithOnlyStringFields>(true); var rowIds = new List <string>(new[] { "id-1", "id-2", "id-3" }); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var rows = db.SelectByIds <ModelWithOnlyStringFields>(rowIds); var dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Is.EquivalentTo(rowIds)); } }
public void CanInsertAndSelectByteArray() { var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } }; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<TypeWithByteArrayField>(true); db.Save(orig); var target = db.SingleById<TypeWithByteArrayField>(orig.Id); Assert.AreEqual(orig.Id, target.Id); Assert.AreEqual(orig.Content, target.Content); } }
public void Can_GetByIds_string_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); var rowIds = new List<string>(new[] { "id-1", "id-2", "id-3" }); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var rows = db.SelectByIds<ModelWithOnlyStringFields>(rowIds); var dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Is.EquivalentTo(rowIds)); } }
public void Can_GetByIds_int_from_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var rowIds = new List<int>(new[] { 1, 2, 3 }); rowIds.ForEach(x => db.Insert(ModelWithFieldsOfDifferentTypes.Create(x))); var rows = db.SelectByIds<ModelWithFieldsOfDifferentTypes>(rowIds); var dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Is.EquivalentTo(rowIds)); } }
public void Can_GetFirstColumnDistinct() { const int n = 5; using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithIdAndName>(true); db.DeleteAll <ModelWithIdAndName>(); n.Times(x => db.Insert(ModelWithIdAndName.Create(0))); var ids = db.ColumnDistinct <int>("SELECT Id FROM ModelWIN"); Assert.That(ids.Count, Is.EqualTo(n)); } }
public void Can_insert_and_select_from_ModelWithComplexTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable <ModelWithComplexTypes>(true); var row = ModelWithComplexTypes.Create(1); db.Insert(row); var rows = db.Select <ModelWithComplexTypes>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithComplexTypes.AssertIsEqual(rows[0], row); } }
public void Can_GetById_from_basic_persistence_provider() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var basicProvider = new OrmLitePersistenceProvider(db); var row = ModelWithFieldsOfDifferentTypes.Create(1); db.Insert(row); var providerRow = basicProvider.GetById<ModelWithFieldsOfDifferentTypes>(1); ModelWithFieldsOfDifferentTypes.AssertIsEqual(providerRow, row); } }
public void Does_table_Exists() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.DropTable<ModelWithIdOnly>(); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, typeof(ModelWithIdOnly).Name), Is.False); db.CreateTable<ModelWithIdOnly>(true); Assert.That( OrmLiteConfig.DialectProvider.DoesTableExist(db, typeof(ModelWithIdOnly).Name), Is.True); } }
public void Can_insert_and_select_from_ModelWithFieldsOfNullableTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfNullableTypes>(true); var row = ModelWithFieldsOfNullableTypes.Create(1); db.Insert(row); var rows = db.Select<ModelWithFieldsOfNullableTypes>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithFieldsOfNullableTypes.AssertIsEqual(rows[0], row); } }
public void Can_Save_table_with_null_fields() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdAndName>(true); db.DeleteAll<ModelWithIdAndName>(); var row = ModelWithIdAndName.Create(0); row.Name = null; db.Save(row); var rows = db.Select<ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(1)); ModelWithIdAndName.AssertIsEqual(rows[0], row); } }
public void CascadesOnDelete() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<TypeWithOnDeleteCascade>(true); db.Save(new ReferencedType { Id = 1 }); db.Save(new TypeWithOnDeleteCascade { RefId = 1 }); Assert.AreEqual(1, db.Select<ReferencedType>().Count); Assert.AreEqual(1, db.Select<TypeWithOnDeleteCascade>().Count); db.Delete<ReferencedType>(r => r.Id == 1); Assert.AreEqual(0, db.Select<ReferencedType>().Count); Assert.AreEqual(0, db.Select<TypeWithOnDeleteCascade>().Count); } }
public void Can_update_ModelWithFieldsOfDifferentTypes_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var row = ModelWithFieldsOfDifferentTypes.Create(1); db.Insert(row); row.Name = "UpdatedName"; db.Update(row); var dbRow = db.GetById<ModelWithFieldsOfDifferentTypes>(1); ModelWithFieldsOfDifferentTypes.AssertIsEqual(dbRow, row); } }
public void Transaction_rollsback_if_not_committed() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithIdAndName>(true); db.DeleteAll<ModelWithIdAndName>(); db.Insert(new ModelWithIdAndName(0)); using (var dbTrans = db.BeginTransaction()) { db.Insert(new ModelWithIdAndName(0)); db.Insert(new ModelWithIdAndName(0)); var rowsInTrans = db.Select<ModelWithIdAndName>(); Assert.That(rowsInTrans, Has.Count.EqualTo(3)); } var rows = db.Select<ModelWithIdAndName>(); Assert.That(rows, Has.Count.EqualTo(1)); } }
public void Can_Store_from_basic_persistence_provider() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithFieldsOfDifferentTypes>(true); var basicProvider = new OrmLitePersistenceProvider(db); var rowIds = new List<int> {1, 2, 3, 4, 5}; var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x)); rows.ForEach(x => basicProvider.Store(x)); var getRowIds = new[] {2, 4}; var providerRows = db.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList(); var providerRowIds = providerRows.ConvertAll(x => x.Id); Assert.That(providerRowIds, Is.EquivalentTo(getRowIds)); } }
public void Can_query_using_float_in_alernate_culuture() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<Point>(true); db.Insert(new Point { Width = 4, Height = 1.123f, Top = 3.456d, Left = 2.345m}); var points = db.Select<Point>(); Console.WriteLine(points.Dump()); Assert.That(points[0].Width, Is.EqualTo(4)); Assert.That(points[0].Height, Is.EqualTo(1.123f)); Assert.That(points[0].Top, Is.EqualTo(3.456d)); Assert.That(points[0].Left, Is.EqualTo(2.345m)); points = db.Select<Point>("Height={0}", 1.123f); // returns no rows! FirebirdSql bug? Assert.That(points.Count>0); } }
public void Can_select_with_filter_from_ModelWithOnlyStringFields_table() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<ModelWithOnlyStringFields>(true); var rowIds = new List<string>(new[] { "id-1", "id-2", "id-3" }); rowIds.ForEach(x => db.Insert(ModelWithOnlyStringFields.Create(x))); var filterRow = ModelWithOnlyStringFields.Create("id-4"); filterRow.AlbumName = "FilteredName"; db.Insert(filterRow); var rows = db.Where<ModelWithOnlyStringFields>(new { filterRow.AlbumName }); var dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Has.Count.EqualTo(1)); Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id)); rows = db.Where<ModelWithOnlyStringFields>(new { filterRow.AlbumName }); dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Has.Count.EqualTo(1)); Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id)); var queryByExample = new ModelWithOnlyStringFields { AlbumName = filterRow.AlbumName }; rows = db.ByExampleWhere<ModelWithOnlyStringFields>(queryByExample, excludeNulls: true); dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Has.Count.EqualTo(1)); Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id)); rows = db.Query<ModelWithOnlyStringFields>( "SELECT * FROM ModelWithOnlyStringFields WHERE AlbumName = @AlbumName", new { filterRow.AlbumName }); dbRowIds = rows.ConvertAll(x => x.Id); Assert.That(dbRowIds, Has.Count.EqualTo(1)); Assert.That(dbRowIds[0], Is.EqualTo(filterRow.Id)); } }
public void Can_insert_table_with_UserAuth() { using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open()) { db.CreateTable<UserAuth>(true); var jsv = "{Id:0,UserName:UserName,Email:[email protected],PrimaryEmail:[email protected],FirstName:FirstName,LastName:LastName,DisplayName:DisplayName,Salt:WMQi/g==,PasswordHash:oGdE40yKOprIgbXQzEMSYZe3vRCRlKGuqX2i045vx50=,Roles:[],Permissions:[],CreatedDate:2012-03-20T07:53:48.8720739Z,ModifiedDate:2012-03-20T07:53:48.8720739Z}"; var userAuth = jsv.To<UserAuth>(); db.Insert(userAuth); var rows = db.Select<UserAuth>(q => q.UserName == "UserName"); Console.WriteLine(rows[0].Dump()); Assert.That(rows[0].UserName, Is.EqualTo(userAuth.UserName)); } }