如何正确删除和重新添加实体数据模型
这里是实体框架的新手。使用VS 2010和SQL Server 2008 Express DB。
添加新表后,我在刷新实体数据模型时遇到问题。因此,我遵循了在这里找到的建议,删除并重新生成模型。
我进入实体数据模型向导的“选择您的数据连接”部分,并选中“将 Web.config 中的实体连接设置另存为:”。然而,我现有的名字后面附加了一个 1。例如,MyDatabaseEntities 现在是 MyDatabaseEntities1。当然,我不希望附加“1”。我杀死了 Web.config 中的现有连接字符串,并删除了解决方案中对该名称的所有引用。然而,当我尝试继续时,出现以下错误:
“‘MyDatabaseEntites’与应用程序设置中的现有属性名称冲突。请选择其他名称”
我在解决方案中的任何位置都找不到对该名称的引用。我可以取消选中该选项,它将继续,但它仍然不会在数据库中添加两个表。接下来,我完全关闭所有内容,重新启动,然后再次尝试。这次我没有收到上面的错误,但我的三个新表中的两个仍然没有添加到 edmx 模型中。
任何想法表示赞赏。而且,即使在 VS2010/.NET 4 中,这似乎仍然有很多错误。请帮助恢复我的信心......我现在想放弃实体框架。根据我迄今为止的经验以及此处发布的其他一些问题,我觉得我将花费更多的时间来追逐实体框架的陌生性,而不是编写有用的代码。
更新:我找到了解决方案。设计器不会显示错误。您必须查看本机 XML(edmx 文件)才能看到错误。请参阅此处:ADO.NET 实体框架:更新向导将不添加表
newbie to Entity Framework here. Using VS 2010 and SQL Server 2008 express DB.
I was having trouble refreshing an Entity Data Model after adding new tables. So, I followed a suggestion I found here to just delete and regenerate the model.
I get to the "Choose Your Data Connection" section of the Entity Data Model Wizard and "Save entity connection settings in Web.config as:" is checked. However, my existing name has a 1 appended to it. For example MyDatabaseEntities is now MyDatabaseEntities1. Of course, I don't want the "1" appended. I killed the existing connection string in Web.config and removed all references to that name in my solution. Yet when I try to continue I'm presented with the following error:
"'MyDatabaseEntites' conflicts with an existing property name in the Application Settings. Please choose a different name"
I can't find a reference to that name anywhere in the solution. I can uncheck that option and it will continue, but it STILL won't add two of the tables in the database. Next, I completely shut everything down, rebooted, and tried again. This time I didn't get the error above, but two of my three new tables still do not get added to the edmx model.
Any ideas are appreciated. Also this seems like it's still pretty buggy even in VS2010/.NET 4. Help restore my faith...I feel like abandoning Entity Framework at this point. Based on my experience so far and some of the other issues posted here, I feel like I'm going to spend more time chasing Entity Framework strangeness than writing useful code.
UPDATE: I found a resolution. The designer doesn't display errors. You have have to look in the native XML (edmx file) to see the errors. See here: ADO.NET Entity Framework: Update Wizard will not add tables
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
该错误是由“App.Config”文件中的设置中剩余的连接字符串引起的(请参阅解决方案资源管理器),它位于本节中:
“connectionStrings”(用尖括号括起来)
只需从那里删除它即可。
The error is caused by leftover connection strings in settings in "App.Config" file (see solution explorer) and it's in this section:
"connectionStrings" (surrounded by angle brackets)
Just delete it from there.
IIS
。来自 web.config 或 app.config 的字符串行
数据模型
并将其重命名为旧名称,IIS
if you develop web app.EntityDataModel
ConnectionString Line from web.config or app.config
Data Model
and rename it like old name,我不知道你的问题的具体答案,但我想我可以推荐一种方法来解决这个冲突。
我通常将 EF 工作分解到一个单独的库中。如果我正在开发 Cyberdyne.Terminator,我会创建一个名为 Cyberdyne.Terminator.Data 的 EF 类库。这样,如果您想删除模型并重新开始,所有内容都与您的依赖文件分开,特别是您的 web.config。
这些可能都无法修复丢失的表。我见过发生这种情况的一件事是如果我添加一个表,然后删除它。它不会再次出现在“添加表”对话框中(您必须重命名它才能显示)。但我认为这在 EF 4.0 中已得到解决。不知道。如果问题仍然存在,您可以尝试重命名该表,重新添加它,然后在出现时将其重命名回来。
EF 确实是一件让人头疼的事。我唯一能告诉你的是,我通常必须解决这些令人头疼的问题,了解问题所在,然后再也不会被它们困扰。如果你不能忍受 EF,你也可以看看 NHibernate——我对此也有很强烈的印象。
I don't know the specific answer to your problem, but I think I can recommend an approach that will clear up this conflict.
I generally break my EF work into a separate library. If I'm working on Cyberdyne.Terminator, I make an EF class library called Cyberdyne.Terminator.Data. That way, if you want to blow away the model and start over, everything is separate from your dependent files, and in particular, your web.config.
None of this is likely to fix the missing tables, probably. The one thing I've seen where this happens is if I add a table, and then delete it. It will not appear again in the "Add Tables" dialog (and you have to rename it to get it to show). But I thought that was fixed in EF 4.0. Dunno. If the problem persists you might try renaming the table, re-adding it, and then renaming it back if it shows up.
EF is a pain in the ass to be sure. The only thing I can tell you is that I've generally had to work through these headaches, learn the issue, and never be bothered by them again. If you can't stand EF, you might also look at NHibernate - I have a very strong impression of that as well.
仔细检查您的连接字符串,然后继续向右滚动。大多数情况下,当这种情况发生在我身上时,Visual Studio 会在另一个连接字符串后面附加一个连接字符串。我已经这样做了几次,并且想知道我的应用程序配置在哪里(不,没有应用程序配置,只有 mvc 中的 Web 配置),所以对话框有点混乱。果然,该连接字符串很可能就隐藏在另一个连接字符串后面!
Double check your connection strings, and keep scrolling to the right. Most often, when this happens to me, Visual Studio has appended a connection string behind another. I've done this a couple times, and wondered where my app config was (no, there is no app config, just web config in mvc), so the dialog is a little confusing. Sure enough, most likely that connection string is lurking directly behind another!
只需按
键并在下拉列表中选择“EntireSolution/CurrentProject”,然后按 Enter。无论在何处生成此名称,它都会向您显示。
我进入 web.config 文件。因此从那里删除生成的完整连接线。并重新添加一次。那么希望您不会再收到此消息。谢谢..
Just press
keys and in dropdown list select 'EntireSolution/CurrentProject', then press enter. where ever this name generated it will show you.
I get into web.config file. so delete that generated complete connection line from there. and re add it again. Then hope you may not get this message again.Thank you..
实际上,这很令人沮丧,因为您试图在 app.config 中查看是否有另一个字符串,而您只看到 1 个字符串,实际上 VS 所做的有时是在同一行中附加第二个字符串。请参阅下面的图片
看起来有 2 个 ConnectionString 吗? (实际上是的)
现在,看这张照片:
您也可以按 Ctrl+ED 格式化配置文件,看看是否还有第二个字符串隐藏在某处。希望这会对某人有所帮助。
Actually this is frustrating, since you trying to see in app.config that if there's a another string and you see only 1 string, Actually What VS does is sometimes append second string in the same line. see this picture below
Does it look like there are 2 ConnectionStrings? (ACTUALLY YES)
Now, see this pic:
Also you can press Ctrl+ED to format the config file and see if there's another second string hiding somewhere. Hope this will help someone.
我很抱歉我的英语
但解决办法很简单。
你必须删除 ado.net
然后,转到app.conf并删除连接字符串<>,
调试您的项目并最终通过 ado.net 添加新数据库
im so sorry for my english
but the solution is simply.
you have to delete the ado.net
then, go to app.conf and delete the connection string<>,
DEBUG your project and finally add the new database through ado.net