edandersen / core-admin

Fully automatic admin site CRUD UI generator for ASP.NET Core and .NET 8
Other
599 stars 111 forks source link

.NET 6 ASP.NET Core support with AddSqllite / AddSqlServer #28

Closed ErikEJ closed 2 years ago

ErikEJ commented 2 years ago

I would like to blog about this great tool, but no DbContext seems to be found, maybe a duplicate of #17?

edandersen commented 2 years ago

Hi Eric, this appears to work fine with .NET 6 as of 2.0 - have you tried the sample project?

ErikEJ commented 2 years ago

No, but I tried a project like this: https://github.com/davidfowl/CommunityStandUpMinimalAPI/blob/main/TodoApi/Program.cs#L8

Maybe the issue is use of "AddSqlite" / "AddSqlServer" instead of the previous AddDbContext ?

edandersen commented 2 years ago

That's interesting, I'll take a look. Thanks.

edandersen commented 2 years ago

Have you added

app.MapDefaultControllerRoute();

To Program.cs?

Here is a working example with SQLLite in a branch - https://github.com/edandersen/core-admin/blob/sqllite/src/DotNetEd.CoreAdmin.DemoAppDotNet6/Program.cs

If you check the repo out and run the DemoAppDotNet6 project it should work.

ErikEJ commented 2 years ago

Great - I will have a look

ErikEJ commented 2 years ago

OMG, I was doing this:

builder.Services.AddCoreAdmin();

builder.Services.AddSqlServer<NorthwindContext>("Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=true;");

Fixed with:

builder.Services.AddSqlServer<NorthwindContext>("Data Source=.\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=true;");

builder.Services.AddCoreAdmin();

Wonder if the docs could be clearer?

ErikEJ commented 2 years ago

Added a PR

pppdns commented 2 years ago

@ErikEJ this fixed the issue for me too! I just had to add builder.Services.AddCoreAdmin() AFTER builder.Services.AddDbContext, not before. (I didn't need app.MapDefaultControllerRoute() btw)