Reputation: 399
I have created a SQL Server database for my application (the ERD is shown here):
This database has already been populated with data from the School MIS, and I wish to "link" it to the application using Entity Framework.
I have already added classes such as Student
, Staff
as model classes within the project.
It might also be worth noting that I intend to use the Roles
feature within ASP.NET to implement access rights.
How can I link this database to Entity Framework, or should I use EF to generate one from code?
Upvotes: 3
Views: 9486
Reputation: 399
First, I enabled migrations to EF Identity by running enable-migrations
(which used the ApplicationDbContext).
I then followed the Entity Framework Code First to an Existing Database method to add a second DbContext into the application and to generate model classes.
Finally, I changed the ApplicationDbContext so that it used the existing database in its connection string and so the ASP.NET Identity tables were created in the existing database.
This does mean that if I want to change the database model, I will need to delete migrations and repeat this process, but it is a working solution to the problem.
Thanks!
Upvotes: 1