Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table missing from 'EF Designer from database' .edmx diagram

I built a simple ADO.Net MVC project in Visual Studio 2015 by following the tutorial found here. My project works, but I wanted to add more tables to the database and create several foreign key relationships between them and the existing tables. I added an ADO.Net Entity Data Model (Project Properties > Add > New Item > Data > ADO.Net Entity Data Model > EF Designer from Data Model) with all tables selected. I'm using the (localdb)\MSSQLLocalDB that's installed with Visual Studio.

My intention was to create my new tables and FK-relationships in the .edmx diagram, then "Forward Engineer" the modified model back into the database. However, only 5 of the 6 tables created by the ASP.NET MVC template were added to the table. The AspNetUserRoles table was not added.

Can anyone explain why the table was not added and what I should have done to create the new tables and key relationships? I prefer to work in a graphical environment as I am not a DB/SQL expert.

like image 965
d ei Avatar asked Nov 11 '15 22:11

d ei


People also ask

How do I find a table in EDMX diagram?

In main menu select View > Other Windows > Entity Data Model Browser (it usually opens in the same panel as Solution explorer). You can navigate the tree list or type the table in text box.

How do I insert a table into a .edmx file?

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.

How do I display a table in Entity Framework?

Right-click the Models folder in the Solution Explorer window and the select the menu option Add, New Item. Select the Data category and select the ADO.NET Entity Data Model template. Give your data model the name MoviesDBModel. edmx and click the Add button.


1 Answers

For anyone looking up this:

If you have a table formed of two Foreign Keys combined to form the Tables Primary Key and no other properties in the table the Entity Framework will not add this table to the Model although it exists in the background.

You do not need the intermediate Join table. The EF will add the Navigation property.

So in this case you would use something like: (User Object).Roles.add(new userrole object); save context changes to update;

like image 164
Mark Homer Avatar answered Oct 03 '22 20:10

Mark Homer