I'm hoping someone can help a fairly new programmer.
I have a Blazor app I have a Console app I have a Class library
The class library contains all of the models and services for both the Blazor app and console app to access. The Blazor app works fine, by creating the service on startup, i.e.
Код: Выделить всё
builder.Services.AddDbContextFactory(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
For example, in the shared library, I have the following method:
Код: Выделить всё
public async Task GetReceiptHeadersAsync(int id) { using var context = factory.CreateDbContext(); return await context.ReceiptHeaders.Where(p => p.Superseeded == false).FirstOrDefaultAsync(p => p.Id == id); }
Is there a way round this, or a way to create a new dbcontext and create a DbContextFactory off of this?
I've tried to create the IDbContextFactory manually, however I get a casting issue between myDbContext and IDBContextFactory
Источник: https://stackoverflow.com/questions/755 ... onsole-app