Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Entity Framework: Update Wizard will not add tables

I added a new ADO.Net Entity Data Model into my project and used the Update Wizard to add tables into the model. Five of the selected tables were added to the design surface. Two other tables will not add. I select them in the wizard and click Finish, yet they never show up on the design surface.

Is this a bug, or are there some situations where a table cannot be added to the model (by design)?


UPDATE: The XML (*.edmx) reveals the problem.

<!--Errors Found During Generation: warning 6013: The table/view 'FooBar.dbo.Roles' does not  have a primary key defined and no valid primary key could be inferred.  This table/view has been excluded. To use the entity you will need to  review your schema, add the correct keys and uncomment it.--> <!--<EntityType Name="Roles">     <Property Name="role_id" Type="decimal" />     <Property Name="role_desc" Type="nvarchar" MaxLength="30" /> </EntityType>--> 
like image 653
Robert Claypool Avatar asked Feb 12 '09 23:02

Robert Claypool


People also ask

How do I add more tables in Entity Framework?

Open edmx file, right click anywhere in the modal and select "Update Model from Database" and follow the instructions and choose the desired tables and SPs. Sometimes even after following these steps, your model will not get updated, close Visual Studio and restart it again.

How do I update EDMX to a new table?

Delete existing model and then update: Delete key to delete all models in the designer. IMPORTANT: Do not save the EDMX at this point if you are using TFS for source control!* Now right-click and select "Update Model from Database" to recreate the entire model again. Rebuild project to propagate changes.


2 Answers

The design surface is different from the entity model. It is possible to have a table in the mapping in your EDMX which does not appear on the design surface. View the file as XML to see if this is the case. In this case, the Update Wizard will not allow you to re-add the tables, since they are already part of the entity model. So, generally speaking, the Update Wizard knows more about your entity model than it does about the design surface, per se.

I don't think that's exactly the situation you're in, but it should give you the general idea for the solution: go into the XML and look for references to the tables in question.

like image 107
Craig Stuntz Avatar answered Sep 20 '22 02:09

Craig Stuntz


Set Primary Keys to all tables or just one unchecked check-box "Allow null" to any column of each table. It works for me :)

like image 20
Parvinder Avatar answered Sep 21 '22 02:09

Parvinder