我在基於C#的代碼中使用了實體框架。我遇到了意想不到的奇怪現象,正在尋找建議。實體框架 - 無法將lambda表達式轉換爲鍵入'string',因爲它不是委託類型
案例1,2,3,4 ... 項目:
RivWorks.dll
RivWorks.Service.dll
RivWorks.Alpha.dll
樣品(所有這些工作):
RivWorks.Alpha.dll:
public static bool EndNegotitation(long ProductID)
{
var product = (from a in _dbFeed.AutoWithImage
where a.AutoID == ProductID select a).FirstOrDefault();
...
}
RivWorks.Service.dll
public static RivWorks.Model.NegotiationAutos.AutoWithImage
GetProductById(long productId)
{
var myProduct = from a in _dbFeed.AutoWithImage
where a.AutoID == productId select a;
return myProduct.FirstOrDefault();
}
public static List<RivWorks.Model.NegotiationAutos.AutoWithImage>
GetProductByCompany(Guid companyId)
{
var myProduct = from a in _dbFeed.AutoWithImage
where a.CompanyID == companyId select a;
return myProduct.ToList();
}
等
案 「怪事」:
RivWorks.Web.Service.dll(WCF項目)
包含的其他項目一樣引用。
public NegotiateSetup GetSetup(string method, string jsonInput)
{
...
long.TryParse(ProductID, out result);
var product = (from a in _dbFeed.AutoWithImage
where a.AutoID == result select a).FirstOrDefault();
...
}
我得到這個編譯時錯誤(單詞「其中」在我的編輯被高亮顯示):
無法轉換lambda表達式到類型「串」,因爲它不是一個委託類型
任何想法會導致這種情況?
這聽起來很奇怪。如果您刪除對「FirstOrDefault」的調用,會發生什麼情況?顯然,在你嘗試使用'product'之後會失敗,但是這個語句是否被編譯? – 2010-01-13 16:52:39
另外,如果將其更改爲'var product = _dbFeed.AutoWithImage.Where(a => a.AutoID == result);'然後會發生什麼?讓我們把查詢表達式從混合中刪除... – 2010-01-13 16:53:20
所有這些例子都失敗了。但是,我在所有代碼片段中都使用了Using語句,發現我缺少一個:使用System.Linq;這解決了錯誤。 –
2010-01-13 17:48:00