https://docs.umbraco.com/umbraco-cms/tutorials/getting-started-with-entity-framework-core
AddUmbracoEFCoreContext is supported Umbraco 12.0.0
I updated the project to Umbraco 12.3.5 because of a recent security patch update now this function keeps giving an error during the add-migration command.
So I tried to use AddUmbracoDbContext and started getting the following error message.
The DbContext of type 'MyContext' cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.
Could someone direct me on how to use AddUmbracoDbContext in Umbraco 12.3.5
Thanks
i
ivodepivo
12/17/2023, 10:50 PM
I don't have a code sample ready, but do you have a context with a constructor like this?
Copy code
c#
public BlogContext(DbContextOptions<BlogContext> options)
: base(options)
{ }
Where you have a DbContextOptions and inherit from base(options)?
ivodepivo
12/17/2023, 10:50 PM
And is it public and not protected/internal
h
hasan_15229
12/17/2023, 11:46 PM
My initial point was Umbraco document needs to be updated as it shows a deprecated method.
Still Here are my codes:
builder.Services.AddUmbracoDbContext(options => options.UseSqlServer(config.GetConnectionString("umbracoDbDSN")));
public MyContext(
DbContextOptions options) : base(options) {
}
The main issue I found Add-migration command required mentioning the context. so if I wrote
add-migration Initialize -context MyContext
It starts working.
EF gets two contexts otherwise.
a
Ambert
12/18/2023, 9:48 AM
Hi Hasan!
As Umbraco is open source, feel free to open a pull request if you've found the answer to correct this! You can find the source on https://github.com/umbraco/UmbracoDocs