/// <summary> /// 多表查询 /// </summary> /// <returns></returns> private Task <int> Test2() { //两张表 var uQueryUser = DB.CreateQuery <EntityModel.User>(); var uQueryRelate = DB.CreateQuery <EntityModel.Relate>(); #region 查询全部 var allQuery = from b in uQueryUser join c in uQueryRelate on b.Relate_ID equals c.ID select new EntityModel.User { ID = b.ID, Name = b.Name, Relate_ID = b.ID, RelateName = c.Name }; var p1 = allQuery.ToList(); #endregion #region 条件查询 var p2 = allQuery.Where(b => b.ID > 1).ToList <EntityModel.User>(); #endregion #region 条件分页查询 QueryArgs queryAga = new QueryArgs(); var wlist = new List <WhereField>(); WhereField wf = new WhereField() { WhereType = WhereType.Like, Field = "test_name", Value = "用户" }; wlist.Add(wf); queryAga.WhereFields = wlist; var result = DB.CreateComQuery().Query <User>(allQuery, queryAga);//.toResult(); #endregion #region json 分页查询 QuerySearchModel qsModel = new QuerySearchModel(); string str = JsonHelper.Serialize(wlist); qsModel.Filters = str; var args = qsModel.toQuery(); var result1 = DB.CreateComQuery().Query <User>(allQuery, args); #endregion return(Task.FromResult(1)); }
/// <summary> /// 单表查询 /// </summary> /// <param name="userName"></param> /// <returns></returns> private Task <int> Test1() { var uQuery = DB.CreateQuery <EntityModel.User>(); #region 查询全部 var allList = uQuery.ToList(); #endregion #region 条件查询 var p = uQuery.Where(b => b.ID > 0 && b.Name.Contains("用户")).ToList <EntityModel.User>(); #endregion #region 条件分页查询 QueryArgs queryAga = new QueryArgs(); var wlist = new List <WhereField>(); WhereField wf = new WhereField() { WhereType = WhereType.Like, Field = "test_name", Value = "用户" }; wlist.Add(wf); queryAga.WhereFields = wlist; var result = DB.CreateComQuery().Query <User>(uQuery, queryAga);//.toResult(); #endregion #region json 分页查询 QuerySearchModel qsModel = new QuerySearchModel(); string str = JsonHelper.Serialize(wlist); qsModel.Filters = str; var args = qsModel.toQuery(); var result1 = DB.CreateComQuery().Query <User>(uQuery, args); #endregion return(Task.FromResult(1)); }