Category: Linq

  • 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… Continue reading

  • ,

    Nullable Tempdata in MVC

    DateTime? FromDate = TempData[“FromDate”] as DateTime?; DateTime? ToDate = TempData[“ToDate”] as DateTime?; int? UserIdInv = TempData[“UserIdInv”] as int?; Continue reading

  • 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(); Continue reading

  • Update multiple Record In List using linq

    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;});     Continue reading

  • Group By and Sum using Linq On Entity

    It requires to get group by with sum. var amount = plod.objProduct.Where(i => i.SID == nslres.SID).GroupBy(s => s.SID).Select(x => new { Totamt = x.Sum(y => y.PrdPrice) }).FirstOrDefault().Totamt;   Continue reading

  • 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 =>… Continue reading