4

I have created a SQL Server database for my application (the ERD is shown here):

MyPortal Entity Relationship Diagram

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?

2
  • 3
    I think you might be looking for database first where you populate an EDMX from the existing database. Check out msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx Commented Feb 27, 2018 at 22:09
  • 3
    It's a question of how you want to maintain moving forward. Code first with an existing database is an option. Reverse engineer your existing database, then modify via code first and migrations moving forward. EDMX is not supported in EF Core. Commented Feb 27, 2018 at 22:23

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.