【发布时间】:2011-06-17 18:02:04
【问题描述】:
我有一个连接几个表的 LINQ To 实体。这是我使用的 LINQ。
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
{
c.EffectiveStartDate,
s.FirstName,
s.LastName,
a.Description,
j.FundingSource
}).FirstOrDefault();
它在 LINQPAD 中运行大约 20 秒,但是,如果我运行生成的 sql 语句,它将只有 1 秒。我猜大部分时间都花在了从 LINQ 语句生成这条 SQL 语句上,但是为什么要花那么长时间呢?
【问题讨论】:
标签: entity-framework linq-to-entities