本文整理汇总了C#中OrmLiteConnectionFactory.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory.GetById方法的具体用法?C# OrmLiteConnectionFactory.GetById怎么用?C# OrmLiteConnectionFactory.GetById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrmLiteConnectionFactory
的用法示例。
在下文中一共展示了OrmLiteConnectionFactory.GetById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_get_data_from_TableWithNamigStrategy_with_GetById
public void Can_get_data_from_TableWithNamigStrategy_with_GetById()
{
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 = "999",
AlbumId = "112",
AlbumName = "ElectroShip",
Name = "MyNameIsBatman"
};
db.Save<ModelWithOnlyStringFields>(m);
var modelFromDb = db.GetById<ModelWithOnlyStringFields>("999");
Assert.AreEqual(m.Name, modelFromDb.Name);
}
OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase();
}
示例2: 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"));
}
}
示例3: 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));
}
}
示例4: CanInsertAndSelectByteArray
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.GetById<TypeWithByteArrayField>(orig.Id);
Assert.AreEqual(orig.Id, target.Id);
Assert.AreEqual(orig.Content, target.Content);
}
}
示例5: 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);
}
}
示例6: Can_retrieve_LastInsertId_from_inserted_table
public void Can_retrieve_LastInsertId_from_inserted_table()
{
using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
{
db.CreateTable<ModelWithIdAndName>(true);
var row1 = ModelWithIdAndName.Create(5);
var row2 = ModelWithIdAndName.Create(6);
db.Insert(row1);
var row1LastInsertId = db.GetLastInsertId();
db.Insert(row2);
var row2LastInsertId = db.GetLastInsertId();
var insertedRow1 = db.GetById<ModelWithIdAndName>(row1LastInsertId);
var insertedRow2 = db.GetById<ModelWithIdAndName>(row2LastInsertId);
Assert.That(insertedRow1.Name, Is.EqualTo(row1.Name));
Assert.That(insertedRow2.Name, Is.EqualTo(row2.Name));
}
}