开发者

Linq to SQL Joining to the Same Table Twice for Two Different Tables

How do I write this SQL in Linq to SQL using C#. I cannot get the join to the status table to both ConsumerApplications and RepairOrderEstimates to work properly. Thanks.

select ca.ConsumerAppID,
       ca.LastName,
       statConsumerApp.StatusName,
       statRepairOrderEstimates.StatusName 
  from ConsumerApplications ca
  join RepairOrderEstimates
    on ca.RepairOrderEstimateID = RepairOrderEstimates.RepairOrderEstimateID
  join Statuses statConsumerApp
    on ca.StatusID = statConsumerApp.StatusID
  join Statuses statRep开发者_StackOverflowairOrderEstimates
    on RepairOrderEstimates.StatusID = statRepairOrderEstimates.StatusID


I think you can do this with something like

from ca in ConsumerApplications
join est in RepairOrderEstimates on ca.RepairOrderEstimateID == est.RepairOrderEstimateID
join statConsumerApp in Statuses on ca.StatusID == statConsumerApp.StatusID
join statEstimate in Statuses on est.StatusID == statEstimate.StatusID
select new {
  ConsumerAppID = ca.ConsumerAppID,
  LastName = ca.LastName,
  AppStatus = statConsumerApp.StatusName,
  EstimateStatus = statEstimate.StatusName,
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜