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

2015-11-12 c# sql-server asp.net-mvc entity-framework

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.

Answers

You did not select AspNetUserRoles when you were initially generating the model. Do use the check boxes to select the tables you want.

To add it, Right click on the designer select "Update Model from Database..." from the context menu. Under the first Tab "Add". expand "Tables", then expand "dbo" and select "AspNetUserRoles" using the check box and other tables you may require. Click Finish button to update the Model and EDMX

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;

Ef requires primary key from table. If primary missing in table than EF will ignore that table .Find details here

You can add a primary key column in cross table . Then problem is resolving

Related