linq to Entities very slow. RRS feed

  • Question

  • I have a LINQ To Entities which join a couple of tables. Here is the LINQ I use.



    var lastestEntry = (from c in etDataContext.Child_HomeVisitor
                                    join s in etDataContext.ServiceCoordinators
                                    on c.HomeVisitorID equals s.ServiceCoordinatorID
                                    join ch in etDataContext.CountyHomeVisitorAgencies
                                    on c.CountyHomeVisitorAgencyId equals ch.CountyHomeVisitorAgencyID
                                    join a in etDataContext.Agencies
                                    on ch.AgencyID equals a.AgencyID
                                    join f in etDataContext.ServiceCoordinatorFundingSourceTypes
                                    on c.PrimaryFundingSourceID equals f.ServiceCoordinatorFundingSourceTypeId
                                    into joinFundingSource
                                    from j in joinFundingSource.DefaultIfEmpty()
                                    where c.ChildID.Equals(childID)
                                    orderby c.EffectiveStartDate descending, c.CreatedDateTime descending
                                    select new

    It runs about 20 seconds in LINQPAD, however, if I run the generated sql statement , it will be only 1 second. I guess most of time is spent on generating this SQL statement from LINQ statement, but why it would take that long?


    Friday, June 17, 2011 6:51 PM


All replies