Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A default DbContext context must exist, or a context factory must be provided (EntityFrameworkManager.ContextFactory). This setting is required for some additional features #47

Closed
joelnotified opened this issue Aug 15, 2017 · 5 comments
Assignees

Comments

@joelnotified
Copy link

Hi!
I'm trying to use BulkSaveChangesAsync together with EF Core (and Postgresql if that makes any difference) in an ASP.NET Core project.

I get the following error:
A default DbContext context must exist, or a context factory must be provided (EntityFrameworkManager.ContextFactory). This setting is required for some additional features

This is the package I use:
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="0.0.1-beta5" />

I have configured EF like this:

services
                .AddEntityFrameworkNpgsql()
                .AddDbContext<AppDataContext>(options =>
                {
                    options.UseNpgsql(connectionString);
                })
                .AddDbContext<DataContext>(options =>
                {
                    options.UseNpgsql(connectionString);
                });

I do not really understand the error message, how should I configure a default DbContext (as you can see I have multiple contexts). Or where should I provide the context factory?

Thank you!

@JonathanMagnan JonathanMagnan self-assigned this Aug 15, 2017
@JonathanMagnan
Copy link
Member

Hello Joel,

Currently, we do not support PostgreSQL for the EF Core version. We will try to add the support during the weekend since almost everything is already here.

About the error, it's caused because there is no default constructor for your context. For EF Core, we modified a little bit our code and it must require now to be able to create a context.

Example:

static ApplicationDbContextPCore()
{
	var options = new DbContextOptionsBuilder();
	options.UseNpgsql(new SqlConnection(My.Config.ConnectionStrings.TestDatabase));
	EntityFrameworkManager.ContextFactory = context => new ApplicationDbContextPCore(options);
}

We will try to document and improve the error message as well.

More information will be provided as soon as we support it.

Best Regards,

Jonathan

@joelnotified
Copy link
Author

joelnotified commented Aug 16, 2017

Alright! Thank you for the answer, looking forward for an updated version then :)

@JonathanMagnan
Copy link
Member

Hello @joelnotified ,

We finally success to release our stable version which supports PostgreSQL ;)

https://www.nuget.org/packages/Z.EntityFramework.Extensions.EFCore/

Let me know if you found some issue.

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

Closing Comment: Fix released

@lexaguilar
Copy link

lexaguilar commented Jan 30, 2019

var auxs = new List<ConciliacionBancariaAux>();

        foreach (var aux in conciliacionViewModel.conciliacionBancariaAux)
        {
            var conciliado= !string.IsNullOrEmpty(aux.Uuid);

            //if(aux.IsNew)
            {
                auxs.Add(new ConciliacionBancariaAux    
                {
                    ProcesoBancoId = procesoBancoId,
                    Fecha = aux.Fecha,
                    Referencia = aux.Referencia,
                    TipoMovimientoId = aux.TipoMovimientoId,
                    Debito = aux.Debito,
                    Credito = aux.Credito,
                    EstadoId = aux.EstadoId,
                    Uuid = aux.Uuid,
                    Conciliado = conciliado,
                    TableInfo = aux.TableInfo,
                    IdOrigen = aux.IdOrigen,
                    IdRef = aux.IdRef, 
                    Arrastrado = !aux.IsNew,
                    IsNew = aux.IsNew,
                    ProcesoBancoIdOld = aux.ProcesoBancoIdOld
                });
            } 
        }

        db.BulkInsert(auxs);

Error : A default DbContext context must exist, or a context factory must be provided 

`<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.1.47" />`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants