Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF DBFirst, table gets removed from model

Something strange is happening in my EF Database-first EDMX model. I wanted to update the model after making some changes in the DB. The update operation removed a table that did not received any changes. That table was present in the model for a long time and never had any problems.

Obviously, I'm getting the Error 11007 : Entity type 'MyTable' is not mapped.

I tried several things:

  • Close the EDMX without saving, retry: same problem.
  • Redo "Update Model from DB", check the box in front of the removed table... But it is not getting added to the model (?)
  • Close Visual Studio, retry: same problem.
  • Try in another EDMX (I have 5-6 models in the solution, all linked to the same (big) DB) : There the table is not removed (!)
  • Rename the table in the DB : With the new name, it IS added.
  • Clean the EDMX's XML from everything that is linked to that table, retry the update: no effect.

What could be causing a particular table to not be added in a particular emdx model file ? This seems like a bug to me.

NB. Before the table is removed, it is listed in the "Refresh" tab of the "Update from DB" Wizard.

VS 2017 15.4.2 (last update done the day before the problem appeared...?)

EDIT - More information : The Table is named "DocumentStatuses" and formed of two columns.

CREATE TABLE [cov].[DocumentStatuses](
    [Id] [int] NOT NULL,
    [Label] [varchar](50) NOT NULL,
CONSTRAINT [PK_DocumentStatus] PRIMARY KEY CLUSTERED ( [Id] ASC )
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

The DocumentStatus entity maps the Id column to an enum. It worked fine until this problem appeared (but it continues to work fine for 2 other entity data models).

EDIT 2

I'm going crazy with this bug. It suddenly appeared, in the same edmx, for 5 others tables that are not linked to each other. I tried to create another EDMX, with another name, and it has the same bug. I tried to add tables one-by-one, and suddenly, the problems appears. No matter wich table I add, the 5 others that were present in the model simply disappear and I get the Error 11007.

If anyone has the tiniest idea, it is really welcome.

EDIT 3

I created a new solution, added my tables to a new entity data model... and the problems remains. EF REFUSES to map the tables. Are there some logs that VS creates when we do "Update from database" ?.

Next step i'll try is to create a VM and try in it.

like image 464
Mik Avatar asked Nov 07 '22 14:11

Mik


1 Answers

I "solved" the problem by renaming the table in the database. This is only a workaround but it's all I could come up with.

like image 128
Mik Avatar answered Dec 15 '22 02:12

Mik