Then you would reference database info something like this: _context.Hikers....
I have the following to display all of my hikers:
public ActionResult Index()
{
return View(_context.Hikers.ToList());
}
*If you don't use a constructor and pass in the ApplicationDbContext, you will get the following:
An unhandled exception occurred while processing the request.
InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So I did get it working for anybody else that runs across this.
Previously, the following would work in .NET Framework: (On the controller - HikerController in my case)
Now in .NET Core, you need a constructor; starts a similar way:
Then you would reference database info something like this:
_context.Hikers...
.I have the following to display all of my hikers:
*If you don't use a constructor and pass in the
ApplicationDbContext
, you will get the following: