我有这样的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