Entity Framework - it is not possible to create a database from my EDMX because new objects are not in the database?

Having received a piece of my application working with Entity Framework 4.1, I needed to add a couple more tables. I created entities and associations in the Model Viewer, and then asked him to create a database from the model.

Immediately I get a selection of validation errors, and a pop-up message tells me that I must clear all the validation errors before I can create the database.

The errors in question are all line by line:

Error 11007: Object type "EntityName" is not displayed.

or

Error 11008: The AssociationName is not displayed.

I get this error once for every new Entity and association I created.

Now I realized that they are not yet tied to the database, this seems quite logical, since they are completely new to the model. This is why I am trying to use the Create Database From Model tools to create a database.

I understand correctly that I can’t create a new database from the model because the new objects and associations that I added to the Model are not in the database yet? If so, how do I get around this?

+4
source share
3 answers

It was found that (as suggested in the hdv comments) an error was lost in the .EDMX file, which was lost in the middle of the Error Message noise. This is due to the field in which I used the key for association, and then deleted, not realizing that the association depends on it.

The error message contained a line in the .EDMX file, so I closed it in the model editor and used Open With > XML Editor to open the source, find the corresponding line and remove the association. This was marked by several more errors in which this link was indicated from other sources, and after deleting these files, I was able to open the file again in Model Viewer, and this allowed me to create a database.

+3
source

Error 11007: Object type "EntityName" is not displayed, it can also be called by a file with a left over a class (for example, entityname.cs ) in the folder of your solution ...

I ran into the same problem: Error 11007: Entity type 'EntityName' is not mapped. in VS2010 using TFS. I believe that this is most likely caused by the use of copy and paste and other changes to new objects in the designer. Even canceling changes to TFS, closing VS2010, etc. Did not work.

During the investigation, even though I returned to the last verified version in TFS, when I looked at the source folder (containing the .edmx file), I found the entityname.cs file associated with the violating object, which I tried to add, then deleted and recreated . This can also be seen using the Show All Files feature in VS2010 Solution Explorer.

Once the deleted file was deleted, EDMX could be edited. After the database schema has been updated to match, we no longer get an error when using the update model from the database (what we do in order to reference custom SQL functions, etc. - a few O / T, which I know).

I hope this helps someone else experience the same problem.

+1
source

Open the edmx editor in xml and check if AssociationSetMapping exists for your association.

0
source

Source: https://habr.com/ru/post/1388493/


All Articles