我想根據下面的SQL編寫一個LINQ查詢。編寫一個LINQ查詢遍歷許多表
基本上這個策略看起來很混亂 - 爲什麼要從MerchantGroupMerchant開始,然後從'語句中做2'?
問題:有沒有更簡單的方法來寫這個LINQ查詢?
var listOfCampaignsMerchantIsInvolvedIn =
(from merchantgroupactivity in uow.MerchantGroupActivities
from merchantgroupmerchant in uow.MerchantGroupMerchants
where merchantgroupmerchant.MerchantU.Id == merchantUIDGuid
select new
{
merchantgroupactivity.ActivityU.CampaignU.Id
}).Distinct();
這裏是表結構:
和SQL:
SELECT DISTINCT Campaign.ID
FROM Campaign
INNER JOIN Activity
ON (Campaign.CampaignUID = Activity.CampaignUID)
INNER JOIN MerchantGroupActivity
ON (Activity.ActivityUID = MerchantGroupActivity.ActivityUID)
INNER JOIN MerchantGroup
ON (MerchantGroup.MerchantGroupUID = MerchantGroupActivity.MerchantGroupUID)
INNER JOIN MerchantGroupMerchant
ON (MerchantGroupMerchant.MerchantGroupUID = MerchantGroup.MerchantGroupUID)
INNER JOIN Merchant
ON (Merchant.MerchantUID = MerchantGroupMerchant.MerchantUID)
WHERE Merchant.ID = 'M1'
創建一個視圖,然後應用Linq2Sql。 –
這當然是一個選項歡呼,但理想情況下,我想現在一切都在LINQ查詢。 –