我有以下例外。我檢查了設計師和班級,機會代碼是一個整數。將字符串轉換爲int時的特定linq異常。 LINQ to Entities不能識別方法'Int32 ToInt32(System.Object)'m
LINQ實體無法識別方法「的Int32 ToInt32(System.Object的)」方法,和這種方法不能被翻譯成表達商店
public tblOpportunity GetOpportunityByCode(string clientCode, string opportunityCode)
{
tblOpportunity opportunity = null;
ConnectionHandler.Invoke<EntityConnection>((connection) =>
{
var context = new xxEntities();
opportunity = context.tblOpportunities.FirstOrDefault<tblOpportunity>(o => o.ClientCode == clientCode && o.OpportunityCode == Convert.ToInt32(opportunityCode));
});
return opportunity;
}
}
public partial class tblOpportunity
{
public int OpportunityCode { get; set; }
你嘗試過'o.OpportunityCode.ToString()== opportunityCode'嗎? – Mzf
你確定它是int類型嗎?因爲它可以是int嗎? (可爲空)或者你可以使用automapper來映射輸出linq查詢到你的領域特定模型,這將減少手動映射的痛苦 – rajansoft1
是的它是好的 –