开发者

linq to Entities very slow

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.CountyH开发者_开发问答omeVisitorAgencies
                                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
                                           {                                                                                         
                                               c.EffectiveStartDate,                                                  
                                               s.FirstName,
                                               s.LastName,
                                               a.Description,
                                               j.FundingSource
                                           }).FirstOrDefault();

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?


EF loads the metadata while executing the first query and this may take some time even with only an average number of tables. Did you check if it runs faster the second time (not in LInqpad but in code)?

Learning the EF: http://www.testmaster.ch/EntityFramework.test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜