【根据主键Id查询数据】
T model = ORM.Get<T>(tblDemo.Id);
【根据兰姆达表达式查询数据】
List<T> list = ORM.Get<T>((it => it.Where(o => o.Mark > 0).OrderBy(o => o.CreateDate)));
【根据兰姆达表达式查询数据(In): where id in(3, 5, 10)】
string[] ids = new string[]{"3", "5", "10"};
List<int> listIds = ids.ToList();
用法1:List<T> list = ORM.Get<T>((it => it.Where(o => o.Id.In(ids))));
用法2:List<T> list = ORM.Get<T>((it => it.Where(o => o.Id.In(listIds))));
用法3:List<T> list = ORM.Get<T>((it => it.Where(o => o.Id.In(1, 2, 3, 5, 6))));
【按条件动态拼接】
var expc = new AiExpConditions<tblORMTest>();
if (string.IsNullOrEmpty(name) == false)
expc.Add(it => it.Where(o => o.String1 == name));
expc.Add(it => it.Where(o => o.Mark > 0).OrderByDescending(o => o.InsertTime));
ORM.Get(expc);
【智能动态拼接(3.2.0.3 版本新增)】
-- 为了进一步提升前后端开发速度,减少代码级别判断是否拼接条件
-- 提供了5个方法:DynamicIn、DynamicLike、DynamicEquals、DynamicGreaterThan、DynamicLessThan
【如果接收的值为 null 则自动忽略拼接的条件】
-- 与 In 类似,where Mobile in('111','222','333')
ORM.Get<T>((it => it.Where(o => o.Mobile.DynamicIn("111,222,333"))
-- 与 Like 类似,where Mobile like '%13666666666%'
ORM.Get<T>((it => it.Where(o => o.Mobile.DynamicLike("13666666666"))
-- 与 = 类似,where Mobile = '13666666666'
ORM.Get<T>((it => it.Where(o => o.Mobile.DynamicEquals("13666666666"))
-- 与 > 类似
!= null:where Mark > 0 and Age > 20
== null:where Mark > 0
ORM.Get<T>((it => it.Where(o => o.Mark > 0 && o.Age.DynamicGreaterThan(20))
-- 与 < 类似
!= null:where Mark > 0 and Age < 20
== null:where Mark > 0
ORM.Get<T>((it => it.Where(o => o.Mark > 0 && o.Age.DynamicLessThan(20))
【根据兰姆达表达式查询数据(Like)】
List<T> list = ORM.Get<T>((it => it.Where(o => o.Id.Like("abc%"))));
【根据Sql条件查询数据(传入值参数化)】
-- 写法1
List<T> list = ORM.GetWhere<T>("where ClassID = @ClassID and Mark > 0", "order by CreateDate"
, new { ClassID = "1" });
-- 写法2
var paramList = new List<MKeyValue>();
paramList.Add("@ClassID", "1");
List<T> list = ORM.GetWhere<T>("where ClassID = @ClassID and Mark > 0", "order by CreateDate"
, paramList);