This sample demonstrates how to implement raw SQL Queries in ASP.NET Core. The main query is calculating the student grade.
This sample consists of 2 separate projects:
- SampleWithEFCore : ASP.NET Core 2.1 with Entity Framework Core
- SampleWithEF6 + EF6: ASP.NET Core 2.1 with data layer separate as library using Entity Framework 6
I used Microsoft sample Contoso University and simply modified it.
- Start with the first project (SampleWithEFCore). When you run it, it will create a local DB because it has a DbInitialzer file.
- When you run the app, call https://localhost:44385/api/Students/GetScore?studentId=1 to get the grade of the student.
* There are different APIs, you can find all of them in the StudentsController.
The implementation of the raw query using Entity Framework Core and ADO.NET are in the StudentRepository. - Now, you can set SampleWithEF6 as StartUp Project.
- Run the app, then click on students in the nav bar. After that, click in user details. You will find the score in the last raw.