如何用左连接在linq中编写sql查询

时间:2016-11-09 13:33:34

标签: asp.net entity-framework linq linq-to-entities

select 
    pm.GenerationID, srv.ServiceID, srv.ServiceName, srv.ServiceDescription, 
    srv.IsProPack, pm.MonthlyPrice, pm.AnnualPrice, ss.freeExpirationDate 
from 
    tbl_BILLING_PricingModels pm 
    inner join tbl_BILLING_Services srv on pm.ServiceID = srv.ServiceId 
    left join tbl_BILLING_SubscribedServices ss on srv.ServiceID = ss.ServiceId 
        and ss.ClientId='3B345E8B-3E6C-40E6-A4B8-E6371B717018' 
where 
    pm.GenerationID = 5 order by srv.ServiceID

如何编写linq查询?

1 个答案:

答案 0 :(得分:0)

请注意,我没有可能测试这个,但如果不正确,你可以按照这个方向:

var p = from pm in tbl_BILLING_PricingModels 
        join srv in tbl_BILLING_Services on pm.ServiceID equals srv.ServiceId nto res
        from ss tbl_BILLING_SubscribedServices on srv.ServiceID = ss.ServiceId && ss.ClientId='3B345E8B-3E6C-40E6-A4B8-E6371B717018' 
        where pm.GenerationID = 5 
        order by srv.ServiceID
        select new { pm.GenerationID,
        srv.ServiceID,
        srv.ServiceName,
        srv.ServiceDescription,
        srv.IsProPack }