Tahir Ansari

Tahir Ansari

  • 255
  • 7.5k
  • 177.9k

asp.net core webAPI

Dec 20 2022 4:05 PM

How to pass connection string in  .net core 7

var connectionString = builder.Configuration.GetConnectionString("HotelListingConnection");
builder.Services.AddDbContext<HotelDbContext>(options => { options.UseSqlServer(connectionString); });  

i'm getting error:  


The type 'HotelDbContext' cannot be used as type parameter 'TContext' in the generic type or method 'EntityFrameworkServiceCollectionExtensions.AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>?, ServiceLifetime, ServiceLifetime)'. There is no implicit reference conversion 
 


Answers (2)