none
Problem with FirstOrDefault and SingleOrDefault RRS feed

  • Question

  • Hi,

      I have a problem with using FirstOfDefault and SingleOrDefault - it works very slowly ! I have about 50 000 users in db and I use that statement:

    var t = (from p in dataContext.UserInPodmiots                                            

    where p.UserID == (Guid)fbaUser.ProviderUserKey                                            

    select p).FirstOrDefault();

        FirstOrDefault works ok but very slow, because without that it works quickly. Problem is how to get First item of this IQuerable collection quickly ?

    Thanx for any help!

    Tuesday, September 4, 2012 7:47 AM

Answers

  • If you think your LINQ works slow then get the FirstorDefault record from your DB by using SQL StoredProcedure.

    LIKE SELECT TOP 1 FROM YOURTABLE .Please refer sql performance tuning before apply this.


    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!


    • Edited by Sambath Raj.C Tuesday, September 4, 2012 9:14 AM
    • Marked as answer by Alexander Sun Wednesday, September 19, 2012 7:00 AM
    Tuesday, September 4, 2012 9:14 AM