如何在.NETCore 3.1&中创建DbContextFactory开拓者 [英] How to Create a DbContextFactory in .NETCore 3.1 & Blazor
本文介绍了如何在.NETCore 3.1&中创建DbContextFactory开拓者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在遵循有关如何设置EF Core使其在Blazor& amp; amp;中安全工作的准则..NET Core 3.1.MS文档在这里:
I'm following guidelines in how to setup EF Core to work safely in Blazor & .NET Core 3.1. The MS documentation is here: https://docs.microsoft.com/en-us/aspnet/core/blazor/blazor-server-ef-core?view=aspnetcore-3.1
在说明中,建议创建一个DbContextFactory,该工厂用于在每个服务中创建dbcontext.在Blazor的世界中一切都说得通,但代码无法像AddDbContextFactory不存在.如果在.Net Core 3.1/EF Core 3中还有另一种方法,我看不到.
In the instructions, advice is to create a DbContextFactory which is used to create a dbcontext in each service. All makes sense in the Blazor world, but the code won't compile as AddDbContextFactory does not exist. If there's another way to do it in .Net Core 3.1/ EF Core 3 - I can't see it.
services.AddDbContextFactory<ContactContext>(opt =>
opt.UseSqlite($"Data Source={nameof(ContactContext.ContactsDb)}.db")
.EnableSensitiveDataLogging());