本文整理汇总了C#中OrmLiteConnectionFactory.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory.Insert方法的具体用法?C# OrmLiteConnectionFactory.Insert怎么用?C# OrmLiteConnectionFactory.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrmLiteConnectionFactory
的用法示例。
在下文中一共展示了OrmLiteConnectionFactory.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transaction_rollsback_transactions_to_different_tables
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));
}
}
示例2: Can_preserve_ModelWithIdOnly_table
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));
}
}
示例3: Can_insert_into_ModelWithFieldsOfDifferentTypes_table
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);
}
}
示例4: Transaction_rollsback_if_not_committed
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));
}
}
示例5: Can_select_with_filter_from_ModelWithOnlyStringFields_table
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));
}
}
示例6: Can_GetById_int_from_ModelWithFieldsOfDifferentTypes_table
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));
}
}
示例7: Can_GetById_string_from_ModelWithOnlyStringFields_table
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"));
}
}
示例8: Can_insert_and_select_from_OrderLineData
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));
}
}
示例9: Can_GetByIds_int_from_ModelWithFieldsOfDifferentTypes_table
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));
}
}
示例10: Can_GetByIds_string_from_ModelWithOnlyStringFields_table
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));
}
}
示例11: Can_GetById_from_basic_persistence_provider
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);
}
}
示例12: Can_insert_and_select_from_ModelWithFieldsOfNullableTypes_table
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);
}
}
示例13: Can_update_ModelWithFieldsOfDifferentTypes_table
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);
}
}
示例14: Can_GetByIds_from_basic_persistence_provider
public void Can_GetByIds_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 => db.Insert(x));
var getRowIds = new[] {2, 4};
var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
var providerRowIds = providerRows.ConvertAll(x => x.Id);
Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
}
}
示例15: Can_query_using_float_in_alernate_culuture
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);
}
}