I am facing an issue while giving the connectionstring to get it connect to PostgreSQL through the AddDbContext()
method in ConfigureServices method of Startup.cs
I'm getting this error while calling the function options.UseNpgsql()
(see the image below).
I have seen other questions regarding this but those are for usesqlserver()
and also they did not solve my problem.
To solve this error "'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'", you should add the Sqlite package. Open your CMD > Go to the path of the project folder, then run this command : dotnet add package Microsoft.EntityFrameworkCore.Sqlite.
The dbContextOptions carries the configuration information needed to configure the DbContext. The dbContextOptions can also be configured using the OnConfiguring method. This method gets the DbContextOptionsBuilder as its argument. It is then used to create the dbContextOptions.
Two things to check:
Are you missing the correct import. The UseNpgsql()
extension method is in the Microsoft.EntityFrameworkCore
namespace which means you should have this line:
using Microsoft.EntityFrameworkCore;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With