加入实体框架但获取错误。 [英] Join in entity framework but fetch error.
本文介绍了加入实体框架但获取错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个模型首先是费用,第二个是Itemmodels。将所有产品存储在具有ID,名称的商品模型中,并仅在费用商店中存储itemId。所以我需要通过加入代码从两个表中获取记录如下。但这是获取错误:
LINQ to Entities无法识别方法'System.String ToString(System.String)'方法,并且此方法无法转换为商店表达式
I have two model first is expense and second is Itemmodels. Store all Product in Itemmodels with id,Name and in expense store only itemId. so i need get record from both table through join code is below. But this is fetch error:
LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression
var data = db.expense
.Join(db.Itemmodels, q => q.ITEM, o => o.id, (q, ITEM) => new { q, ITEM })
.Where(o => o.q.EntryDate.ToString() == DateTime.Now.ToString("dd/MM/yyyy")).Where(o => o.q.Manager.ToString() == managerName).Where(o => o.q.THROUGH.ToString() != "CashTransfer")
.ToList();
推荐答案
请阅读我对这个问题的评论。
这也应该有效:
Please, read my comment to the question.
This should work as well:
var data = db.expense
.Join(db.Itemmodels, q => q.ITEM, o => o.id, (q, ITEM) => new { q, ITEM })
.Where(o => o.q.EntryDate == DateTime.Today && o.q.Manager == managerName && o.q.THROUGH != "CashTransfer")
.ToList();
试试这样
try like this
string currentDate = DateTime.Now.ToString("dd/MM/yyyy");
var data = db.expense.Join(db.Itemmodels, exp => exp.ITEMID, im => im.id, (exp, im) => new { exp = exp, im = im })
.Where(o => o.exp.EntryDate == currentDate && o.exp.Manager == managerName && o.exp.THROUGH != "CashTransfer")
.ToList();
这篇关于加入实体框架但获取错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文