如何在linq中编写以下sql join?
select Campaign.CampaignName, COUNT(*) as total
from Campaign join CampaignAsset
on CampaignAsset.CampaignId=Campaign.CampaignId
where Campaign.UserProfileId=65
Group By Campaign.CampaignName
答案 0 :(得分:0)
试试这个:
YourDatabaseName dataContext = new YourDatabaseName();
var result = from c in dataContext.Campaign
join ca in dataContext.CampaignAsset on c.CampaignId equals ca.CampaignId into j1
from j2 in j1.DefaultIfEmpty()
where c.UserProfileId = 65
group j2 by c.CampaignName into grouped
select new { CampaignName = grouped.Key, Count = grouped.Count() };