我有這樣的LINQ查詢:LINQ到實體無法識別方法 'System.String格式(System.String,System.Object的,System.Object的)'
private void GetReceivedInvoiceTasks(User user, List<Task> tasks)
{
var areaIds = user.Areas.Select(x => x.AreaId).ToArray();
var taskList = from i in _db.Invoices
join a in _db.Areas on i.AreaId equals a.AreaId
where i.Status == InvoiceStatuses.Received && areaIds.Contains(a.AreaId)
select new Task {
LinkText = string.Format(Invoice {0} has been received from {1}, i.InvoiceNumber, i.Organisation.Name),
Link = Views.Edit
};
}
它有問題,雖然。我正在嘗試創建任務。對於每個新任務,當我將鏈接文本設置爲像「Hello」這樣的常量字符串時,這很好。然而,上面我試圖使用發票的屬性來構建屬性linktext。
我得到這個錯誤:
base {System.SystemException} = {"LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression."}
任何人都知道爲什麼嗎?任何人都知道這樣做的另一種方式,使其工作?
是,錯過了這一點原本 – AnonyMouse 2012-04-09 21:21:58
可能重複[LINQ到實體無法識別方法「System.String的ToString()」方法(http://stackoverflow.com/questions/4121863/linq- to-entities-does-not-recognized-the-method-system-string-tostring-method) – 2013-12-12 13:32:23