Ado.Net实体数据模型未正确更新

时间:2021-05-14 02:09:11

I've done the following steps: - Open visual studio
- Create new item
- Select "ADO.Net Entity Data Model"
- Point it to an existing database
- Accept all the defaults.
- It then adds a "Model1.edmx" file to my solution and the corresponding "Model1.Designer.cs" file.

我已经完成了以下步骤: - 打开visual studio - 创建新项目 - 选择“ADO.Net实体数据模型” - 将其指向现有数据库 - 接受所有默认值。 - 然后它将“Model1.edmx”文件添加到我的解决方案和相应的“Model1.Designer.cs”文件中。

However in the output I get the following error:
"ERROR: Unable to generate model because of the following exception: 'Value does not fall within the expected range.'."

但是在输出中我得到以下错误:“错误:由于以下异常,无法生成模型:'值不在预期范围内。'。”

I've created a model from this database before so I dont think the error is a result of complex table design (which it's not).

我之前已经从这个数据库创建了一个模型,所以我不认为错误是复杂表设计的结果(事实并非如此)。

Has anyone else hit this error?

还有其他人遇到此错误吗?

Thanks

10 个解决方案

#1


I had a similar problem. The reason was pretty simple. I've forgotten to set a primary key in one of my tables. Hope it helps.

我有类似的问题。原因很简单。我忘了在我的一张桌子里设置一把主键。希望能帮助到你。

#2


Ok....
I think I might have a solution. I've just done the following and it worked.

好的....我想我可能有一个解决方案。我刚刚完成了以下工作。

  • Create a new project
  • 创建一个新项目

  • Add an Ado data model to it.
  • 添加Ado数据模型。

  • So the ONLY thing in the project is the model and it does not reference any other projects so it can stand and build on it's own.
  • 所以项目中唯一的东西就是模型,它没有引用任何其他项目,所以它可以站立并建立在它自己的基础上。

  • I got the error I was mentioning above in this project
  • 我得到了上面在这个项目中提到的错误

  • Delete the Model1.edmx file.
  • 删除Model1.edmx文件。

  • Remove the project reference to "System.Data.Entity.dll" (this was the key)
  • 删除项目引用“System.Data.Entity.dll”(这是关键)

  • Delete the connectionStrings out of "App.config"
  • 从“App.config”中删除connectionStrings

  • Rebuild the Project
  • 重建项目

  • Add the "ADO.Net Entity Data Model" back into your project.
  • 将“ADO.Net实体数据模型”添加回项目中。

It now works.
Un-nerving.
But it works.

它现在有效。取消nerving。但它的确有效。

#3


Ok.
I was able to readd it. Here's what I did.

好。我能够读到它。这就是我做的。

All the steps above in the bullet points plus:

子弹点上面的所有步骤加上:

  • Shut down Visual Studio 2008
  • 关闭Visual Studio 2008

  • restart Sql Server 2005
  • 重启Sql Server 2005

  • Reopen Visual Studio 08.
  • 重新打开Visual Studio 08。

Still stumped on how to resolve this.

仍然难以理解如何解决这个问题。

#4


Please check whether the primary key has been defined for the table. If you open the entity model in xml editor, you should be able to see commented error message, the comment might help you!

请检查是否已为该表定义主键。如果您在xml编辑器中打开实体模型,您应该能够看到注释错误消息,注释可能对您有所帮助!

#5


When I'm unable to open the 'Design View' while clicking on the model.edmx file I Unload the project in VS2008 and then load it back up again and it seems to fix that problem.

当我在单击model.edmx文件时无法打开“设计视图”时,我在VS2008中卸载项目,然后再次加载它,它似乎解决了这个问题。

#6


I experienced the same issue with a MYSQL database using Ria services.

我使用Ria服务遇到了与MYSQL数据库相同的问题。

Solution:
I found the entity model requires a primary key in at least one table when multiple tables are imported.
The primary key for my table was also set to auto increment.

解决方案:我发现实体模型在导入多个表时至少需要一个表中的主键。我的表的主键也设置为自动增量。

#7


You can add one table to the model first and when the edmx file is created, you can update model from the database. It worked for me. I wish it solve ur prblem too.

您可以先将一个表添加到模型中,然后在创建edmx文件时,可以从数据库中更新模型。它对我有用。我希望它也解决你的问题。

cheers Parminder

#8


I've just been investigating a similar issue. It turns out that Entity Framework outputs additional error information in the Messages section of the Error List window in Visual Studio.

我刚刚调查了类似的问题。事实证明,Entity Framework在Visual Studio的“错误列表”窗口的“消息”部分中输出了其他错误信息。

As you can see it's much more useful than the generic error that appears in the Output window. This was crucial in helping me to solve my problem.

正如您所看到的,它比输出窗口中显示的一般错误更有用。这对帮助我解决问题至关重要。

Ado.Net实体数据模型未正确更新

#9


I am having the same problem .

我有同样的问题 。

Reason seems to be simple : lack of Primary Key Column.

理由似乎很简单:缺少主键列。

#10


I had same problem, the easy solution is : delete your model from visual studio and and new ado.net model with same name, before that delete all connection string from config file

我有同样的问题,简单的解决方案是:从visual studio删除你的模型和新的同名ado.net模型,然后从配置文件中删除所有连接字符串

#1


I had a similar problem. The reason was pretty simple. I've forgotten to set a primary key in one of my tables. Hope it helps.

我有类似的问题。原因很简单。我忘了在我的一张桌子里设置一把主键。希望能帮助到你。

#2


Ok....
I think I might have a solution. I've just done the following and it worked.

好的....我想我可能有一个解决方案。我刚刚完成了以下工作。

  • Create a new project
  • 创建一个新项目

  • Add an Ado data model to it.
  • 添加Ado数据模型。

  • So the ONLY thing in the project is the model and it does not reference any other projects so it can stand and build on it's own.
  • 所以项目中唯一的东西就是模型,它没有引用任何其他项目,所以它可以站立并建立在它自己的基础上。

  • I got the error I was mentioning above in this project
  • 我得到了上面在这个项目中提到的错误

  • Delete the Model1.edmx file.
  • 删除Model1.edmx文件。

  • Remove the project reference to "System.Data.Entity.dll" (this was the key)
  • 删除项目引用“System.Data.Entity.dll”(这是关键)

  • Delete the connectionStrings out of "App.config"
  • 从“App.config”中删除connectionStrings

  • Rebuild the Project
  • 重建项目

  • Add the "ADO.Net Entity Data Model" back into your project.
  • 将“ADO.Net实体数据模型”添加回项目中。

It now works.
Un-nerving.
But it works.

它现在有效。取消nerving。但它的确有效。

#3


Ok.
I was able to readd it. Here's what I did.

好。我能够读到它。这就是我做的。

All the steps above in the bullet points plus:

子弹点上面的所有步骤加上:

  • Shut down Visual Studio 2008
  • 关闭Visual Studio 2008

  • restart Sql Server 2005
  • 重启Sql Server 2005

  • Reopen Visual Studio 08.
  • 重新打开Visual Studio 08。

Still stumped on how to resolve this.

仍然难以理解如何解决这个问题。

#4


Please check whether the primary key has been defined for the table. If you open the entity model in xml editor, you should be able to see commented error message, the comment might help you!

请检查是否已为该表定义主键。如果您在xml编辑器中打开实体模型,您应该能够看到注释错误消息,注释可能对您有所帮助!

#5


When I'm unable to open the 'Design View' while clicking on the model.edmx file I Unload the project in VS2008 and then load it back up again and it seems to fix that problem.

当我在单击model.edmx文件时无法打开“设计视图”时,我在VS2008中卸载项目,然后再次加载它,它似乎解决了这个问题。

#6


I experienced the same issue with a MYSQL database using Ria services.

我使用Ria服务遇到了与MYSQL数据库相同的问题。

Solution:
I found the entity model requires a primary key in at least one table when multiple tables are imported.
The primary key for my table was also set to auto increment.

解决方案:我发现实体模型在导入多个表时至少需要一个表中的主键。我的表的主键也设置为自动增量。

#7


You can add one table to the model first and when the edmx file is created, you can update model from the database. It worked for me. I wish it solve ur prblem too.

您可以先将一个表添加到模型中,然后在创建edmx文件时,可以从数据库中更新模型。它对我有用。我希望它也解决你的问题。

cheers Parminder

#8


I've just been investigating a similar issue. It turns out that Entity Framework outputs additional error information in the Messages section of the Error List window in Visual Studio.

我刚刚调查了类似的问题。事实证明,Entity Framework在Visual Studio的“错误列表”窗口的“消息”部分中输出了其他错误信息。

As you can see it's much more useful than the generic error that appears in the Output window. This was crucial in helping me to solve my problem.

正如您所看到的,它比输出窗口中显示的一般错误更有用。这对帮助我解决问题至关重要。

Ado.Net实体数据模型未正确更新

#9


I am having the same problem .

我有同样的问题 。

Reason seems to be simple : lack of Primary Key Column.

理由似乎很简单:缺少主键列。

#10


I had same problem, the easy solution is : delete your model from visual studio and and new ado.net model with same name, before that delete all connection string from config file

我有同样的问题,简单的解决方案是:从visual studio删除你的模型和新的同名ado.net模型,然后从配置文件中删除所有连接字符串