Home > other >  Argument 1: cannot convert from 'Microsoft.EntityFrameworkCore.DbContextOptions' to '
Argument 1: cannot convert from 'Microsoft.EntityFrameworkCore.DbContextOptions' to '

Time:12-26

public class AuthContext : IdentityDbContext
{
    public AuthContext(DbContextOptions options) : base(options)
    {}
}

In the above code snippet : options sent as parameter to base keyword is giving the same error :

Argument 1: cannot convert from 'Microsoft.EntityFrameworkCore.DbContextOptions' to 'string'

CodePudding user response:

The IdentityDbContext constructor is expecting an argument from type string. You are passing it a type DbContextOptions so you're getting that error.

The string you probably want to pass is the name of the relevant connection string which is located in the web config file.

For example:

// web config file

<connectionStrings>
   <add name="AuthContextName" connectionString="your-connection-string" providerName="System.Data.SqlClient" />
</connectionStrings>

// your AuthContext class

public class AuthContext : IdentityDbContext
{
   public AuthContext(DbContextOptions options) : base("AuthContextName")
   {}
 }
  • Related