通用数据访问层示例
Model:
class test : Lm.Common.DAL.IModelBase
{
[Lm.Common.DAL.Identity]
public long Id { get; set; }
public string Name { get; set; }
}
方法:
var con = System.Configuration.ConfigurationManager.ConnectionStrings"ConnectionString".ConnectionString;
var helper = new Lm.Common.DAL.Sql.SqlDAL(con);
//增
var id = helper.Insert<test>(() => new test() { Name = "tom" });
var id2 = helper.Insert<test>(new test() { Name = "jim" });
//删
helper.Delete<test>(t => t.Name == "tom");
//改
helper.Update<test>(t => new test() { Name = "jim2" }, t => t.Name == "jim");
helper.Update<test>(new test() { Id = 300001, Name = "jim3" }, t => t.Name == "jim2");
//查
var list = helper.Select<test>(t => t.Name == "jim3");
var list2 = helper.Select<test>(() => new test() { Name = "" }, () => new test() { Id = 0 }, OrderByOption.ASC, t => t.Name == "jim3");
long recordCount;
var list3 = helper.Select<test>(1, 1, out recordCount, () => new test() { Name = "" }, () => new test() { Id = 0 }, OrderByOption.ASC, t => t.Name == "jim3");

Last edited Sep 10, 2012 at 11:53 AM by liuming, version 1

Comments

No comments yet.