![](/img/trans.png)
[英]LINQ - If table doesn't contains any data left outer join query return a exception
[英]How can I modify this linq query to return some empty fields instead of just omitting the data that doesn't fit the join?
public IQueryable<RecentlyCreatedAssetViewModel> getRecentlyCreatedAssetsByCompanyID(int companyID)
{
return (from a in db.Assets
join ab in db.AssetBundles on a.AssetID equals ab.AssetID
join b in db.Bundles on ab.BundleID equals b.BundleID
where a.CompanyID == companyID && a.AssetTypeID == 11 && a.IsActive == true && a.ShowInResults == true
orderby a.CreateDate descending
select new RecentlyCreatedAssetViewModel { AssetID = a.AssetID, AssetName = a.AssetName, AssetTypeID = a.AssetTypeID, BundleIcon = b.BundleIcon, BundleName = b.BundleName }).Take(10);
}
事實證明,我還想找回一些db.AssetBundles中沒有關系的db.Assets,但是我不知道如何做到這一點,我想把空格(空字符串)放在Bundle的位置當沒有關系時,RecentCreatedAssetViewModel的字段。 這個查詢不會返回一個在連接中沒有關系的資產,但是如何更改它以便它們只是將空字符串放入丟失的數據中?
在查詢中使用LEFT JOIN來完成工作。
更多信息可以在W3Schools找到。
你需要的是執行左外連接,檢查MSDN中join
子句的引用,然后向下滾動到標題為'左外連接'的部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.