none
How do i increase the performance of linq querry? RRS feed

  • Question

  • How do i increase the performance of below linq querry?
    while running it it throw an error of "System.OutOfMemoryException".
    Note: i have a lots of record in "XrmContext.sun_POSSet" entity

    var a = (from temple in XrmContext.sun_POSSet
                        select new POS()
                        {
                            id = temple.Id,
                            Country = temple.sun_sun_country_sun_POS == null ? "" : temple.sun_sun_country_sun_POS.sun_name,
                            CountryId = temple.sun_sun_country_sun_POS == null ? "" : temple.sun_sun_country_sun_POS.Id.ToString(),
                            stringint = temple.sun_sun_stringint_sun_placeofstu == null ? "" : temple.sun_sun_stringint_sun_placeofstu.sun_name,
                            stringintId = temple.sun_sun_stringint_sun_placeofstu == null ? "" : temple.sun_sun_stringint_sun_placeofstu.Id.ToString(),
                            FullName = temple.sun_contact_sun_POS.FullName,
                            EMail = temple.sun_contact_sun_POS.EMailAddress1,
                            MobilePhone = temple.sun_contact_sun_POS.MobilePhone

                        }).ToList<POS>();
    Monday, October 14, 2013 3:14 PM

Answers

  • Unsure if I am stating the obvious.

    Remember not to do the ToList() until you really need it.

    A linq query is just a piece of sql text until it is executed, so if you later toss it into a grid or something then you only need the first 20 or so rows.

    Wednesday, October 16, 2013 7:12 AM
  • Hello,

    For the error message “System.OutOfMemoryException”, there is an article regarding it:

    http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx

    And for complex query in Entity Framework, my suggestion is that we can use the store procedure.

    For using store procedure, we can eliminate the time for converting LinQ expression to sql command.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 15, 2013 2:33 AM
    Moderator

All replies

  • Hello,

    For the error message “System.OutOfMemoryException”, there is an article regarding it:

    http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx

    And for complex query in Entity Framework, my suggestion is that we can use the store procedure.

    For using store procedure, we can eliminate the time for converting LinQ expression to sql command.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 15, 2013 2:33 AM
    Moderator
  • Unsure if I am stating the obvious.

    Remember not to do the ToList() until you really need it.

    A linq query is just a piece of sql text until it is executed, so if you later toss it into a grid or something then you only need the first 20 or so rows.

    Wednesday, October 16, 2013 7:12 AM