Closed NickMaev closed 3 years ago
Have you tried with latest dev templates? I guess rc2 templates are based on .net core 3.1 and not .net 5
Have you tried with latest dev templates? I guess rc2 templates are based on .net core 3.1 and not .net 5
It seems that the dev
branch contains old templates:
https://github.com/OrchardCMS/OrchardCore/blob/dev/src/OrchardCore.Cms.Web/Program.cs
Looks like templates needs update for EF as is looking for CreateHostBuilder
method
The other solution that i am using in my 3.1 project is to create design time factory as below.
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlServer("******");
return new ApplicationDbContext(optionsBuilder.Options);
}
}
The other solution that i am using in my 3.1 project is to create design time factory as below.
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext> { public ApplicationDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>(); optionsBuilder.UseSqlServer("******"); return new ApplicationDbContext(optionsBuilder.Options); } }
Custom "Design time factory" has a lot of disadvantages such as:
Agree, this only helps you if you are not using DI to configure your Context options
Agree, this only helps you if you are not using DI to configure your Context options
... and you can't share your connection string from the appsettings.json
or appsettings.[env].json
For my specific use case, for connection strings, I use command line with arguments and manage my uid/pwd in secret manager.
Is the solution here to update the templates to use CreateHostBuilder
?
@deanmarcussen Sure! template can be updated for EF
Btw, It's unrelated to OrchardCore CMS's connection string as OC's connection string is stored per Tenant under App_Data
@deanmarcussen Sure! template can be updated for EF
Btw, It's unrelated to OrchardCore CMS's connection string as OC's connection string is stored per Tenant under App_Data
It would be great to add some examples how to init the EC Core for tenants in the right way. 😉
@NickMaev OC is not using EF. Also each tenant can have it's own yessql.db
@NickMaev OC is not using EF. Also each tenant can have it's own
yessql.db
I know it. But EF Core is the most popular ORM.
Dapper is quite popular too and you can use it with YesSQL.
@Skrypt @deanmarcussen I guess we can update the template to have CreateHostBuilder
to align with latest ASP.NET Web application template.
@NickMaev this will help EF to read connection string from appsettings
, However be aware that the change you are proposing is not related to OC's database connection string and EF will not connect to any tenant specific yessql.db
as OC's connection string is stored under App_Data
Describe the bug
When I tried to add initial Entity Framework Core migration it couldn't create the database context.
To Reproduce
Steps to reproduce the behaviour:
Test
.WebApp
from the latestdev
branch using the following commands:Core
;ApplicationDbContext
in theCore
project and one entity type.Expected behavior
Migration will be created successfully.
Screenshots
Solution
The problem was in the
Program.cs
. I renamed theBuildHost
static method toCreateHostBuilder
and changed the return type toIHostBuilder
.Before:
Program.cs
After:
Program.cs