开发者

How to properly delete and re-add Entity Data Model

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 refer开发者_JS百科ence 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


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.


  1. Restart IIS if you develop web app.
  2. Restart Visual Studio After Deleting The EntityDataModel Connection String Line from web.config or app.config
  3. Add New Entity Data Model and rename it like old name,


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.


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!


Just press

Ctrl+F

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..


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

How to properly delete and re-add Entity Data Model

Does it look like there are 2 ConnectionStrings? (ACTUALLY YES)

Now, see this pic:

How to properly delete and re-add Entity Data Model

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.


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

TO ADD ADO.NET
RIGHT CLICK ON YOUR PROJECT NAME, THEN, ADD NEW ITEM, DATA AND SEARCH ADO.NET...

I hope help you, have good day!
angelsantacruzm
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜