3
我試圖寫一個單一的查詢,其中將包括的兩個條件之一,基於輸入變量:重新使用基於布爾值LINQ查詢
!(from o in db.Products.Where(x => x.Company_ID == cid && x.IsDeleted != true)
或
(from o in db.Products.Where(x => x.Company_ID == cid && x.IsDeleted != true)
我現在的方法,覆蓋前一個條件,如下所示。我已經包含productExists,它將成爲決定我是否希望從上面獲得條件#1或#2的參數。
public IQueryable<ProductImportViewModel> AllImports(int id, bool productExists)
{
return (from t1 in db.Products_Staging
where (t1.ImportFileId == id) && !(from o in db.Products.Where(x => x.Company_ID == cid && x.IsDeleted != true)
select o.ProductName).Contains(t1.ProductName)
select new ProductImportViewModel
{
Id = t1.Id
}
}
如果有人能幫助我,我會非常感激。
感謝。這幾乎是我所做的。我只是想知道是否有一個更簡潔的方法來做到這一點! – Nick 2012-03-30 11:00:46
更新了答案 – Arion 2012-03-30 11:07:49