How to Connect Database using DBFirst Approach in Entity Framework

The Database First Approach provides an alternative to the Code First and Model First approaches to the Entity Data Model, and it creates model codes (classes, properties, DbContext, etc.) from the database in the project, and those classes become the link between the database and controller.

I'll recommend you read the "Code First" article since there are many basics covered in "Code First Approach in Entity Framework" (), where first we create model codes (classes, properties, DbContext), and then these model classes create a database for us at run time, and that's why we called it "Code First".

public interface IDashboardRepository
{
    Task<IActionResult> GetBarChartDashboard(int d, int m, int y, int w);

    Task<IActionResult> GetMonthFilterData();
    Task<IActionResult> GetWeekFilterData();

}

 public DbSet<ApiEndPoint> ApiEndPoint { get; set; }

Dashboard Repository

public async Task<IActionResult> GetBarChartDashboard(int d, int m, int y, int w)
{
    try
    {
        List<ApiEndPoint> list;
        var dbContext = await dbContextProvider.GetDbContextAsync();
        string sql = "spGetDashboardData {0}, {1}, {2}, {3}";

        list = dbContext.ApiEndPoint.FromSqlRaw<ApiEndPoint>(sql, d, m, y, w).ToList();

        //var populationList = PopulationDataAccessaLayer.GetUsStatePopulationList();
        return new OkObjectResult(list);
    }
    catch (Exception)
    {
        throw;
    }
}