实体框架 - 无效的列名称'* _ID“ [英] Entity Framework - Invalid Column Name '*_ID"

查看:212
本文介绍了实体框架 - 无效的列名称'* _ID“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把这个缩小到了Code First和Database的第一个EF之间的一些问题,但是我不知道如何解决它。我会尽可能的尽可能的清楚,但我老实说,我自己在这里忘了一些理解。这是实体框架4.4



我继承了一个实体框架被使用的项目,但是很多实际的文件被删除,没有任何真正的方法回去。我重新添加了EF(数据库首先),并复制了该项目构建的T4设置。它生成所有数据库模型的代码版本和DBContext代码文件。



如果我的连接字符串看起来像一个正常的.NET连接字符串,我收到一个无效列的错误名称ProcessState_ID不存在。 ProcessState_ID根本不在代码库中,它不在EDMX文件或任何东西。这似乎是查询中的一些自动EF转换。



当我将连接字符串与Entity Framework模型匹配时,它的工作正常。



现在尝试将以前的代码与Entity Framework相匹配,我想保留正常.NET连接字符串。



所以我这里有两个问题:
1.从代码中的一个正常的连接字符串到一个EF连接字符串是什么好的方法?
2.有没有另外修复,我看不到停止无效的列名错误?

解决方案

检查你是否有任何ICollections。



我想到的是当你有一个ICollection引用一个表,没有列可以找出,它为您创建一个尝试使表之间的连接。这特意发生在ICollection,并驱使我蝙蝠试图弄清楚。


I've narrowed this down to some issue between Code First and Database first EF, but I'm not sure how to fix it. I'll try to be as clear as I can, but I honestly am missing some of the understanding here myself. This is Entity Framework 4.4

I inherited a project where Entity Framework was used, but many of the actual files were deleted with no real way to go back. I re-added EF (Database first) and replicated a T4 setup that the project was built around. It generated code versions of all the database models and a DBContext code file.

If my connection string looks like a "normal" .NET connection string I get an error about an invalid column Name "ProcessState_ID" does not exist. ProcessState_ID is not in the code base at all, it is not in the EDMX file or anything. This appears to be some automatic EF conversion in the query.

When I make the connection string match the Entity Framework model it works fine.

Now in trying to match the previous code with Entity Framework I'd like to keep the "normal" .NET connection string.

So I have two questions here: 1. What is a good way to go from a normal connection string to an EF connection string in code? 2. Is there another fix here that I'm not seeing to stop the invalid column name error?

解决方案

Check to see if you have any ICollections.

What I have figured out is when you have an ICollection that references a table and there is no column that it can figure out, it creates one for you to try to make the connection between the tables. This specifically happens with ICollection and has driven me "batty" trying to figure it out.

这篇关于实体框架 - 无效的列名称'* _ID“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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