2016-07-12 91 views
0
var assignresult = (from i in _Objcontext.DistributorProductMappings 
        where i.ProductId == items.ProductID && i.DistributorId == items.DId && i.UpdatedDate == items.UpdatedDate 
        select (int.Parse(i.Purchases) + int.Parse(i.StockTakeback)).ToString() 
        ).FirstOrDefault() ?? "0"; 

此語句失敗不工作convertionsLINQ到實體無法識別方法方法

+0

什麼錯誤失敗? –

+0

{「Message」:「LINQ to Entities無法識別方法Int32 Parse(System.String)方法 ,並且此方法無法轉換爲存儲表達式。」} –

回答

2

你的LINQ表達式將被轉換爲表達該SQL瞭解到,在這種情況下int.Parse不會有等價轉換。

要解決此問題,使用Convert.ToInt32()代替int.Parse

+0

爲什麼您認爲支持Convert.ToInt32? ?事實是,沒有任何**支持任何從字符串到其他數據類型的轉換方法。 –

相關問題