1

I've been experiencing a lot of weird things with the Entity Framework designer in visual studio 2015 Professional. If I try to updated the model from the database it will delete all of the mappings of existing entities and replace the mappings with only the one I updated. If I add a relationship to existing entities it will delete all existing entity classes. The only way to update anything in the designer is to write it all out in XML.

Am I doing something wrong or is there something wrong with the file integrity maybe? I've found workarounds that say I have to completely delete the model and redo it from the database every time if I want to make a change. Updating the Model from the database. Even with this the auto-mapping isn't correct.

It shouldn't be this difficult, that's why I'm lead to believe that maybe something in the files that is making it lose it's integrity after copying it from the previous developer. Or is something else maybe the culprit?

Braden
  • 135
  • 1
  • 11
  • I think it’s normal for EntityFramework and may be the steps in the link you’ve provided can help you too.. sometimes you drag and drop table into designer, or make equivalent changes directly in designer or source code – boateng May 25 '18 at 21:30
  • I've tried the steps that "Gone Coding" says to try in the link I supplied. When updating it after deleting everything it doesn't map it correctly. Could it maybe be something in the T4 template? – Braden May 25 '18 at 22:29
  • First try to verify it with small dB change which wouldn’t break anything such increase column length.. Then try the usual clean solution/rebuild, rename the db file.. Look for errors in output console, enable all errors.. – boateng May 25 '18 at 22:55
  • Any changes to the DB breaks the designer. If I update the designer with anything it will break it. Even if it's changing the length of a column. – Braden May 29 '18 at 16:28
  • What error displays when you make corresponding dB change in a designer.. – boateng May 29 '18 at 16:33
  • When I do Right Click in the model designer -> Update model from database and run through the wizard and select the table from the database to update, I get a `Error 11007: Entity Type '(Entity)' is not mapped.` (where Entity is the table) and it unmaps every single entity. If I try to add an Association between two existing entities it deletes **ALL** associations between all entities except for the new association I added. – Braden May 29 '18 at 20:42
  • This post mentions the error can be caused by permission on db account used https://stackoverflow.com/a/45388836/3254405 – boateng May 29 '18 at 22:20
  • `This happens also when you import tables via diagram in edmx and then you point in app.config to different instance of database (switching from dev db to test db for example)` This comment may actually be very relevant because I am taking over the project and moved it to my user account from the previous developer from source control. How can I tell what the original settings were? When I create the connection it doesn't change the App.config – Braden May 30 '18 at 17:42
  • Yes this would explain it.. It’s probably used his domain account if app.config has integrated security, so your account should be given admin rights on the domain and in sql server.. Alternatively try with sql account like “sa”.. Also open VIsual Studio as admin by right click “Run as Administrator”.. – boateng May 30 '18 at 18:01
  • I have admin rights to the server and the domain so that's not an issue. I tried also running Visual Studio as administrator and no change. What's weird is if I delete the model entities and re-add them it seems to work. However I get a ton of errors when doing so. The different workstations is where I'm leaning towards but I'm not sure where to find the file that sets that. – Braden May 30 '18 at 22:42
  • See if you can create and run this sample app without any problem https://www.itsolutions-inc.com/news-and-training/article/5-steps-to-a-working-website-using-entity-framework-code-first/ – boateng May 31 '18 at 00:03
  • Creating a new project works fine and dandy. It's an existing project that's been moved to a new workstation is what I am having a problem with. – Braden May 31 '18 at 04:14
  • Try adding your dB file to new project, if it works copy other C# files as well.. – boateng May 31 '18 at 12:58
  • 1
    Please see my response below. – Braden May 31 '18 at 20:06

1 Answers1

1

What fixed it was instead of deleting the entire model from the project, I just deleted the Entities from the designer and recreated the entire model from the database. What threw me off when I tried this was it brought in some new fields that weren't in the model before and some table names had changed.

Braden
  • 135
  • 1
  • 11