I am working on an ASP.Net Core 2 MVC Application.
I am generating one controller per table for my backoffice with this command:
dotnet aspnet-codegenerator --project . controller -name MYTABLEController -m MYTABLE -dc MYDBContext
(replace MYTABLE and MYDBContext are examples).
Here is what the csharp Controller looks like:
namespace MYPROJECT.Controllers
{
public class MYTABLEController : Controller
{
private readonly MYDBContext _context;
public ContactsController(MYDBContext context)
{
_context = context;
}
Has you can see it creates a constructor which accepts one parameter: the database object (entityframework).
When i call the web page, i get an error on this context because it is not initialized.
Here what i have to do to make it work:
namespace MYPROJECT.Controllers
{
public class MYTABLEController : Controller
{
private readonly MYDBContext _context = new MYDBContext();
public ContactsController()
{
}
So my question are:
Is there a best way to correct this problem ? I am wondering if it is really a bug or if i miss something.
Look and feel of each generated chtml view is very ugly. Are there some options to get something more sexy ?
Thanks