这是我现在收到的错误:
The argument types 'Edm.String' and 'Edm.Decimal' are incompatible for this operation. Near equals expression, line 1, column 156.
我知道这个错误是一个兼容性问题,但经过表并看到参数匹配并且我认为声明正确后,我需要知道这引用的代码行。我唯一会质疑的是在表中声明为money的数据,但我将它们声明为十进制。这是炸弹的代码
public ActionResult Details(int PVID = 0, int PMID = 0, decimal AID = 0.00M, decimal TID =0.00M, string TyID = null, string NID = null, decimal AmID = 0.00M, decimal PID = 0.00M, string TNID = null, string INID = null, DateTime? DEID = null, decimal IBID = 0.00M, decimal PBID = 0.00M, DateTime? LMDID = null)
{
tblDenialReport tbldenialreport = db.tblDenialReport.Find(PVID, PMID, AID, TID, TyID, NID, AmID, PID, TNID, INID, DEID, IBID, PBID, LMDID);
if (tbldenialreport == null)
{
return HttpNotFound();
}
return View(tbldenialreport);
}
感谢您的帮助
答案 0 :(得分:1)
您应该将主键或复合键作为参数传递给DbSet<TEntity>.Find Method
。您在这里做错了:
tblDenialReport tbldenialreport = db.tblDenialReport.Find(PVID, PMID, AID, TID, TyID, NID, AmID, PID, TNID, INID, DEID, IBID, PBID, LMDID);
DbSet<TEntity>.Find Method
使用主键值尝试查找上下文跟踪的实体。如果要使用上述参数搜索tblDenialReport,则可以按以下方式执行:
public ActionResult Details(int PVID = 0, int PMID = 0, decimal AID = 0.00M, decimal TID =0.00M, string TyID = null, string NID = null, decimal AmID = 0.00M, decimal PID = 0.00M, string TNID = null, string INID = null, DateTime? DEID = null, decimal IBID = 0.00M, decimal PBID = 0.00M, DateTime? LMDID = null)
{
tblDenialReport tbldenialreport = db.tblDenialReport.SingleOrDefault(r=>
r.PVID == PVID && r.PMID == PMID && r.AID == AID &&
r.TID ==TID && r.TyID == TyID && r.NID == NID && r.AmID == AmID &&
r.PID == PID && r.TNID == TNID && r.INID == INID && r.DEID == DEID &&
r.IBID == IBID && r.PBID == PBID && r.LMDID == LMDID);
if (tbldenialreport == null)
{
return HttpNotFound();
}
return View(tbldenialreport);
}
但是,我强烈建议您只在函数名中传递tblDenialReport的唯一键,然后按以下方式执行:
public ActionResult Details(int tblDenailReportId)
{
tblDenialReport tbldenialreport = db.tblDenialReport.Find(tblDenailReportId);
if (tbldenialreport == null)
{
return HttpNotFound();
}
return View(tbldenialreport);
}
答案 1 :(得分:-1)
基于错误消息,我猜这个错误是由于db.tblDenialReport.Find(...)
期望一个整数,但你也传递了字符串和小数。