c# - 错误:其中一个主键值的类型与实体中定义的类型不匹配
问题描述
我不确定为什么会收到此错误。我以前可以工作,现在不行。这是内部异常错误消息:
EntitySqlException:参数类型“Edm.Int32”和“Edm.String”与此操作不兼容。在 WHERE 谓词附近,第 1 行,第 78 列。
这是它挑选出来的代码行:
Attending attending = db.Attendings.Find(userId);
这是控制器上下文中的代码:
public ActionResult Attendees(int? id)
{
var userId = User.Identity.GetUserId();
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Attending attending = db.Attendings.Find(userId);
if (attending == null)
{
return HttpNotFound();
}
PopulateBeverageDropDownList(attending.BeverageId);
return View(attending);
}
我已经查看了 stackoverflow 和 Google,但即使我发现了类似的问题,我仍然无法弄清楚如何解决我自己的问题。
基本上我要做的是同时使用我的一个模型中的 PK 和 asp.net 身份中的 userId。这曾经可以正常工作,但我不知道弹出此错误的原因是什么。这是我的存储库的链接,用于查看完整的代码:https ://github.com/alec9876/Firepit/tree/master/Firepit
任何帮助表示赞赏!
解决方案
推荐阅读
- python - 在 Deepnote 上安装 Conda
- typescript - 如何将函数的参数转换为具有从函数参数名称派生的命名属性的接口?
- python - 在 Django DetailView 中引用 ForeignKey
- ios - 如何检查 Swift URL 是否是目录
- kofax - 如何使用 KTA SDK 创建图像导入作业?
- javascript - 如何在 html img 标签中使用二进制图像?
- python - 如何使此条目小部件显示文本?
- python - 脑奇辣椒python SDK
- c++ - Visual Studio 导出 .editorconfig 没有 c++ 的内容
- python - 如何获得(自动)包装列↔列中视图的宽度?