本文整理汇总了C#中System.Db.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Db.Find方法的具体用法?C# Db.Find怎么用?C# Db.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Db
的用法示例。
在下文中一共展示了Db.Find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
var db = new Db(new MyConfig());
// execute following code in a transaction, but don't commit
using (new TransactionScope())
{
// find by id
var emp = db.Find<Employee>(1);
Console.WriteLine("FOUND ENTITY : \n{0}\n", emp);
// update
emp.EmployeeName = "Hoge";
db.Update(emp);
Console.WriteLine("UPDATED ENTITY : \n{0}\n", emp);
// delete
db.Delete(emp);
Console.WriteLine("DELETED ENTITY : \n{0}\n", emp);
// insert
emp = new Employee { EmployeeName = "Allen", DepartmentId = 2 };
db.Insert(emp);
Console.WriteLine("INSERTED ENTITY : \n{0}\n", emp);
// query and map results to entities. parameters are bindable with "Anonymous Types".
var empList = db.Query<Employee>(@"
select
e.EmployeeId,
e.EmployeeName,
e.DepartmentId,
e.VersionNo
from
Employee e
where
e.DepartmentId = /* emp.DepartmentId */0
", new { emp });
Console.WriteLine("QUERRY RESULTS AS ENTITIES :");
foreach (var e in empList)
{
Console.WriteLine(e);
}
Console.WriteLine();
// query and map results to dynamic objects. parameters are bindable with "Anonymous Types".
var empList2 = db.Query<dynamic>(@"
select
e.EmployeeId,
e.EmployeeName,
e.DepartmentId,
e.VersionNo
from
Employee e
where
e.DepartmentId = /* emp.DepartmentId */0
", new { emp });
Console.WriteLine("QUERY RESULTS AS DYNAMIC OBJECTS :");
foreach (var e in empList2)
{
Console.WriteLine("EmployeeId={0}, EmployeeName={1}", e.EmployeeId, e.EmployeeName);
}
Console.WriteLine();
// call procedure
var procedure = new ProcResultAndOut { EmployeeId = 1 };
db.Call(procedure);
Console.WriteLine("PROCEDURE OUTPUT VALUE : \n{0}\n", procedure.EmployeeCount);
Console.WriteLine("PROCEDURE RESULT ENTITIES :");
foreach (var e in procedure.Employees)
{
Console.WriteLine(e);
}
Console.WriteLine();
// execute arbitrary SQL
var rows = db.Execute("delete from Employee");
Console.WriteLine("AFFECTED ROWS : \n{0}\n", rows);
}
Console.ReadKey();
}