I need export DbContext to library in nuget package for reutilize in various projects

0

i have this code in my library

Entrega.cs

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

public string NumeroDeEnvio { get; set; }

public int MotivoId { get; set; }

public int SubmotivoId { get; set; }
        
public string SucursalId { get; set; }
        
public string CodigoComprobante { get; set; }
        
public string Observaciones { get; set; }
        
public string ResultadoServicioV8 { get; set; }
        
public bool Reintentar { get; set; }
        
public bool Activo { get; set; }
        
public DateTime Created_At { get; }
        
[Timestamp]
public DateTime Updated_At { get; set; }

AplicatonContext.cs

public AplicatonContext(DbContextOptions options): base(options) { }

public DbSet<Entrega> Entregas { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder){ }

and in my WebApi when configure services startup.cs

builder.ConfigureServices((ctx, services) =>
{
    services.AddDbContext<AplicatonContext(opts=> opts.UseSqlServer(ctx.Configuration["ConnectionString"]));

but this code raise exception whit error

System.InvalidOperationException
  HResult=0x80131509
  Message=The database provider attempted to register an implementation of the 'IRelationalTypeMappingSource' service. This is not a service defined by Entity Framework and as such must be registered as a provider-specific service using the 'TryAddProviderSpecificServices' method.
  Source=Microsoft.EntityFrameworkCore

Why is this happening?

c#
.net
entity-framework
nuget-package
dbcontext
asked on Stack Overflow Jan 27, 2021 by Santiago

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0