First, Inner Join
Request is a query condition var result = from a in db. TableAjoin B in db. TableBOn a.id equals b.IDwhere a.username = = Request. UserName | | A.mobile = = Request. MobileSelect New Responseinfo {UserName = UI. UserName,UserID = ui.id,Mobile = UI. Mobile,Value = UE. Value };
second, left JoinRequest is a query condition var result = from Si in db. TableAjoin AI in db. TableB on Si. UserID equals ai.id into LjtablebFrom AI in Ljtableb.defaultifempty ()join PI in db. TableC on Si. ProductID equals pi.id into LjtablecFrom Pi in Ljtablec.defaultifempty ()join PS in DB. Tabled on Si. Specid equals ps.id into ljtabledFrom PS in Ljtabled.defaultifempty ()Select New Inforesposne {ID = si.id,Displayid = pi. Displayid,ProductID = si. ProductID,ProductName = pi. ProductName,BarCode = pi. BarCode,specid = si. Specid,Created = si. Created };
Second, dynamic Add query conditions and pageString if (!string. Isnullorwhitespace (Request. Displayid)) {result = result. Where (p = P.displayid = = Request. Displayid);} The string contains if (!string. Isnullorwhitespace (Request. UserName) {userInfo = Userinfo.where (p = p.username.contains (Request). UserName));} Number, State type if (request. Amount!=null) {result = result. Where (p = p.amount = = Request. Amount);} Time range if (request. Stockinstart = null) {result = result. Where (p = p.created >= request. Stockinstart);} Time range if (request. Stockinend = null) {result = result. Where (p = p.created <= request. Stockinend);} var response = new Logresponse (); response. TotalCount = result. Count (); response. DataList = result . OrderByDescending (p = p.created) . Skip (Request. PAGEINDEX-1) * Request. PageSize) . Take (Request. PageSize) . ToList ();
Various queries for LINQ to SQL