本文整理汇总了C#中BLToolkit.Data.DbManager.GetTable方法的典型用法代码示例。如果您正苦于以下问题:C# DbManager.GetTable方法的具体用法?C# DbManager.GetTable怎么用?C# DbManager.GetTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLToolkit.Data.DbManager
的用法示例。
在下文中一共展示了DbManager.GetTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMediaSetting
private void GetMediaSetting(DbManager db)
{
var query = from m in db.GetTable<DataMedia>()
join s in db.GetTable<DataMediaSetting>() on m.IdMedia equals s.IdMedia
where m.IdLanguageData == 33 && s.IdLanguageDataI == 33
orderby m.Media
select
new
{
s.Activation,
m.IdMedia,
m.Media,
s.CaptureCode
};
if (!true)
query = query.Where(r => r.Activation < 10);
var res = query.ToList();
var mediae = res.Select(r => new Media
{
ID_MEDIA = r.IdMedia,
MEDIA = r.Media,
CaptureCode = r.CaptureCode,
IsActivate = r.Activation < 10,
}).ToList();
}
示例2: LoadEntries
/// <summary>
/// Загружает все записи
/// </summary>
/// <returns>The entries.</returns>
protected override IEnumerable<GuestbookEntry> LoadEntries()
{
using (var db = new DbManager())
{
var query = from entry in db.GetTable<DbGuestbookEntry>()
join user in db.GetTable<DbGuestbookUser>() on entry.UserId equals user.Id
select new GuestbookEntry { User = user.Name, Message = entry.Message };
return query.ToList();
}
}
示例3: ShouldMapAssociationForChild
public void ShouldMapAssociationForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field4")
.NewRow("TestOne");
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<AssociationThis2Dbo>()
.MapField(_ => _.FieldThis1, "ThisId")
.MapField(_ => _.FieldThis3)
.Association(_ => _.FieldThis1).ToOne(_ => _.FieldOther3)
.MapTo(db);
var table = db.GetTable<AssociationThis2ChildDbo>();
// when
var dbo = (from t in table select t.FieldThis3.FieldOther4).First();
// then
Assert.AreEqual("TestOne", dbo, "Fail result for many");
conn.Commands[0]
.Assert().AreField("ThisId", "Fail this key");
conn.Commands[0]
.Assert().AreField("FieldOther3", "Fail other key");
conn.Commands[0]
.Assert().AreField("FieldOther4", "Fail other result");
Assert.AreEqual(3, conn.Commands[0].Fields.Count, "More fields");
}
}
示例4: ParameterPrefixTest
public void ParameterPrefixTest()
{
try
{
using (var db = new DbManager(new MySqlDataProvider(), "Server=DBHost;Port=3306;Database=nodatabase;Uid=bltoolkit;Pwd=TestPassword;"))
{
db.GetTable<Person>().ToList();
}
}
catch (DataException ex)
{
var number = ex.Number;
}
}
示例5: Test
public void Test([DataContextsAttribute(ExcludeLinqService=true)] string context)
{
var ids = new long[] { 1, 2, 3 };
using (var db = new DbManager(context))
{
var q =
from t1 in db.GetTable<Table2>()
where t1.Field3.Any(x => ids.Contains(x.Field1))
select new { t1.Field2 };
var sql = q.ToString();
Assert.That(sql.IndexOf("INNER JOIN"), Is.LessThan(0));
}
}
示例6: SaveEntry
/// <summary>
/// Сохраняет запись
/// </summary>
/// <param name="entry">Entry.</param>
protected override void SaveEntry(GuestbookEntry entry)
{
using (var db = new DbManager())
{
var dbEntry = new DbGuestbookEntry ();
dbEntry.Message = entry.Message;
var dbUser = db.GetTable<DbGuestbookUser>().SingleOrDefault (u => u.Name == entry.User);
if (dbUser == null)
{
dbUser = new DbGuestbookUser { Name = entry.User };
dbUser.Id = Convert.ToInt32(db.InsertWithIdentity (dbUser));
}
dbEntry.UserId = dbUser.Id;
dbEntry.Id = Convert.ToInt32(db.InsertWithIdentity(dbEntry));
}
}
示例7: ShouldMapTableNameForChild
public void ShouldMapTableNameForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1")
.NewRow(1);
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<TableNameDbo>()
.TableName("TableNameDboT1")
.MapTo(db);
// when
db.GetTable<TableNameChildDbo>().ToArray();
// then
conn.Commands[0]
.Assert().AreTable("TableNameDboT1", "Fail mapping");
}
}
示例8: ShouldMapValueForMemberForChild
public void ShouldMapValueForMemberForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1", "Field2")
.NewRow(true, false);
using (conn)
using (var db = new DbManager(conn))
{
#warning bug for maping TO db
// fluent config
new FluentMap<MapValueMemberDbo>()
.MapField(_ => _.Field1)
.MapValue("result true", true)
.MapValue("result false", false)
.MapField(_ => _.Field2)
.MapValue("value true", true)
.MapValue("value false", false)
.MapTo(db);
var table = db.GetTable<MapValueMemberChildDbo>();
// when
var dbo = (from t in table select t).First();
// then
Assert.AreEqual("result true", dbo.Field1, "Not map from value1");
Assert.AreEqual("value false", dbo.Field2, "Not map from value2");
}
}
示例9: ShouldMapTrimmableForChild
public void ShouldMapTrimmableForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1")
.NewRow("test ");
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<TrimmableDbo>()
.Trimmable(_ => _.Field1)
.MapTo(db);
var table = db.GetTable<TrimmableChildDbo>();
// when
var dbo = (from t in table select t).First();
// then
Assert.AreEqual("test", dbo.Field1, "Not trimmable");
}
}
示例10: ShouldMapIgnoreForChild
public void ShouldMapIgnoreForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1")
.NewRow(10, 1);
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<MapIgnoreSelectDbo>()
.MapIgnore(_ => _.Field2)
.MapTo(db);
var table = db.GetTable<MapIgnoreChildDbo>();
// when
(from t in table where t.Field1 == 10 select t).First();
// then
conn.Commands[0]
.Assert().AreNotField("Field2", "Field exists");
}
}
示例11: ShouldMapIgnoreInsert
public void ShouldMapIgnoreInsert()
{
// db config
var conn = new MockDb()
.NewNonQuery();
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<MapIgnoreInsertDbo>()
.MapIgnore(_ => _.Field2)
.MapTo(db);
// when / then
new SqlQuery<MapIgnoreInsertDbo>(db).Insert(new MapIgnoreInsertDbo { Field1 = 20, Field2 = 2 });
AssertExceptionEx.AreException<LinqException>(
() => db.GetTable<MapIgnoreInsertDbo>().Insert(() => new MapIgnoreInsertDbo { Field1 = 10, Field2 = 1 })
, "Fail for linq");
// then
conn.Commands[0]
.Assert().AreNotField("Field2", "Field exists");
Assert.AreEqual(1, conn.Commands[0].Parameters.Count, "Fail params");
}
}
示例12: People2
public Table<Person> People2(DbManager db)
{
return db.GetTable<Person>();
}
示例13: ShouldFailMapValueForInsert
public void ShouldFailMapValueForInsert()
{
// db config
var conn = new MockDb()
.NewNonQuery()
.NewNonQuery();
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<MapValueMemberDbo>()
.MapField(_ => _.Field1)
.MapValue("result true", true)
.MapValue("result false", false)
.MapField(_ => _.Field2)
.MapValue("value true", true)
.MapValue("value false", false)
.MapTo(db);
var table = db.GetTable<MapValueMemberDbo>();
// when
table.Insert(() => new MapValueMemberDbo { Field1 = "result true", Field2 = "value false" }); // linq
db.Insert(new MapValueMemberDbo { Field1 = "result true", Field2 = "value false" }); // other?
// then
var i1 = conn.Commands[0].CommandText.IndexOf("result true", StringComparison.Ordinal);
Assert.IsTrue(-1 == i1, "Not map to value1 for linq");
var i2 = conn.Commands[0].CommandText.IndexOf("value false", StringComparison.Ordinal);
Assert.IsTrue(-1 == i2, "Not map to value2 for linq");
Assert.AreEqual(true, conn.Commands[1].Parameters[0].Value, "Not map to value1");
Assert.AreEqual(false, conn.Commands[1].Parameters[1].Value, "Not map to value2");
}
}
示例14: ShouldMapInheritanceMappingSelectChild
public void ShouldMapInheritanceMappingSelectChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1", "Field2")
.NewRow(1, 1);
using (conn)
using (var db = new DbManager(conn))
{
// fluent config
new FluentMap<InheritanceMappingChDbo>()
.TableName("tt")
.InheritanceMapping<InheritanceMappingChDbo1>(11111)
.InheritanceMapping<InheritanceMappingChDbo2>(22222)
.InheritanceField(_ => _.Field2)
.MapTo(db);
var table = db.GetTable<InheritanceMappingChDbo1>();
// when
var dbos = (from t in table select t).ToArray();
// then
Assert.IsInstanceOfType(dbos[0], typeof(InheritanceMappingChDbo1), "Invalid type");
Assert.IsTrue(conn.Commands[0].CommandText.ToLower().Contains("where"), "Not condition");
Assert.IsTrue(conn.Commands[0].CommandText.ToLower().Contains("11111"), "Fail condition value");
conn.Commands[0]
.Assert().AreField("Field2", 2, "Not in where part");
}
}
示例15: ShouldMapValueForTypeForChild
public void ShouldMapValueForTypeForChild()
{
// db config
var conn = new MockDb()
.NewReader("Field1", "Field2", "Field3")
.NewRow("one", "two", true);
using (conn)
using (var db = new DbManager(conn))
{
#warning bug for property any different types
#warning bug for maping TO db
// fluent config
new FluentMap<MapValueTypeDbo>()
.MapValue(1, "one", "1")
.MapValue(2, "two")
.MapValue(3, true)
.MapTo(db);
var table = db.GetTable<MapValueTypeChildDbo>();
// when
var dbo = (from t in table select t).First();
// then
Assert.AreEqual(1, dbo.Field1, "Not map from value1");
Assert.AreEqual(2, dbo.Field2, "Not map from value2");
Assert.AreEqual(3, dbo.Field3, "Not map from value3");
}
}