How to properly delete and re-add Entity Data Model
Asked Answered
G

7

18

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

Godfather answered 6/1, 2011 at 17:19 Comment(3)
Just to comment on the "'MyDatabaseEntites' conflicts with an existing property name in the Application Settings. Please choose a different name": It seems that VS looks in ALL .config files for the entire solution after the name, not just the one that belongs to the project to which the Data Model is being added. So you have to remove the setting from ALL .config files in the solution.Myongmyopia
possible duplicate of ADO.NET Entity Framework: Update Wizard will not add tablesLouisville
Delete all existing connection string from web config file and build the application. Now you can use the existing property names.Skald
P
20

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.

Phidippides answered 25/3, 2012 at 0:26 Comment(2)
I deleted my connection string but was still getting the error message. Had to restart VSIvette
I'm getting this issue in VS15 however there is no connectionstring in my web.config and i have no app.config.Hummocky
D
4
  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,
Dovev answered 8/6, 2012 at 2:20 Comment(0)
H
1

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.

Honig answered 6/1, 2011 at 17:59 Comment(2)
Thanks for the response Chris. That's a good suggestion on the separate library. I did find a resolution to my issue here: #544471 I should have searched a little more before posting.Godfather
Wow...that is crazy. That really ought to be a popup message rather than buried in the XML.Honig
M
1

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!

Monte answered 31/3, 2017 at 1:51 Comment(1)
so true, same thing happened to me. can't even find through Search solutionDayna
C
0

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

Chilon answered 2/7, 2017 at 14:27 Comment(1)
didn't help. i tried searching though the whole solution.Dayna
D
0

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

enter image description here

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

Now, see this pic: enter image description here

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.

Dayna answered 6/5, 2018 at 9:47 Comment(0)
F
-2

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
Faxon answered 17/5, 2016 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.