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.
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With