Contains in Linq with entity

Sometimes we require to use In or Not in operator in LINQ. below is the example var setToRemove = “Approved,Rejected”.Split(‘,’); inv.StatusList = context.BindDropDown(fieldName: “SaneInv”, pageName: “SaneInvoice”).AsEnumerable().Where(i=>setToRemove.Contains(i.dmnValue_Text)). Select(x => new SelectListItem { Text = x.dmnValue_Text, Value = x.dmnValue_ID.ToString(), Selected = false }).ToList(); if tou want to use Not in use have to use ! operator before…

Read More

Linq in Array in c#

Linq can be implemented in array with c#, below is code example of linq with array. var GroupCount = Request.QueryString[“AllchkIDs”].ToString().Split(‘,’).Where(i => i != Request.QueryString[“GroupBy”]).FirstOrDefault();…

Read More

Sometime it requires to update multiple records in List using linq, previous process was for loop, but using below example using linq , update can be done for list

 plod.objProduct.Where(i=>i.SID==sid).ToList().ForEach(u=>{u.ShipCharg=shpchrg;u.ShipType=shptype;});

 

 

Update Multiple Row using Linq

some time it requires to update multiple record using linq , for selecting single value you have to use Dirstdefault() , but for selecting multiple value you have to use list like below var userId=Convert.ToInt32(outuserId.Value); var res = context.tblCarts.Where(i => i.Cookies_Id == Cartcokie.Value).ToList(); res.ForEach(a => a.User_Id = userId); context.SaveChanges();  …

Read More