实体框架试图检索不存在的列 [英] Entity Framework trying to retrieve non existent column

查看:96
本文介绍了实体框架试图检索不存在的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图从数据库中检索VideoCollection项目,但是获取 {无效的列名称User_Id。} - 当我设置断点时,我可以看到EF是尝试选择User_Id列,但它不存在于Cs对象或数据库模式中。 (它确实存在于另一个表中,但这不应该重要)。有没有办法调试为什么会发生这种情况?

I'm trying to retrieve the VideoCollection items from the database, but getting {"Invalid column name 'User_Id'."} - when I set a breakpoint I can see that the EF is trying to select User_Id column but it doesn't exist in the Cs object or the database schema. (It does exist in another table but that shouldn't matter). Is there anyway to debug why this is happening?

推荐答案

你有一个User类可以引用VideoCollection吗?如果是这样,你可能需要明确定义两者之间的关系。就像这样,看起来,EF推断出VideoCollection应该包含定义关系的外键 User_Id

Do you have a User class that has a reference to a VideoCollection? If so, you probably need to explicitly define the relationship between the two. As it is, it looks like EF is inferring that the VideoCollection should contain a foreign key, User_Id that defines the relationship.

这篇关于实体框架试图检索不存在的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆