You must Sign In to post a response.
  • Category: LINQ

    To make linq query faster

    Hi All,

    What should I do to make the following linq query faster? The database got heaps of records in it. This query actually followed by foreach loop and then again another query and foreach loop. It takes much time to load.
    Help will be appreciated. Thank you.

    var hours = from hr in objHours.Distinct()

    where hr.EmployeeID == empGuid && hr.JobId == j.JID && hr.CatId == j.CatId.ToInt() && hr.Date.Year == DateTime.Now.Year
    orderby hr.TID descending
    select new
    {
    hr.Hour,
    hr.Date,
    hr.CatId
    };
  • #763193
    Hai AP,
    You can use instead lambda expression:

    var hours = objHours.Distinct()
    .Where(a=>a.EmployeeID == empGuid)
    .Where(a =>a.JobId == j.JID)
    .Where(a=>a.CatId == j.CatId.ToInt())
    .Where(a =>a.Date.Year == DateTime.Now.Year)

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #763206
    Hi,

    Thank you very much Pawan. Could you please help me in doing that with IEnumerable?

    Thank you once again.


  • Sign In to post your comments