Home > Net >  C# cannot convert to 'Microsoft.EntityFrameworkCore.DbContextOptions'
C# cannot convert to 'Microsoft.EntityFrameworkCore.DbContextOptions'

Time:09-26

Trying to learn C# when I ran into the following error:

CS1503: Argument 1: cannot convert from 
'BookAPI.Models.DbContextOPtions<BookAPI.Models.BookContext>' 
to 'Microsoft.EntityFrameworkCore.DbContextOptions'

I'm just following the tutorial here: https://www.youtube.com/watch?v=sWJayOop4k8

I am creating the file called BookContext.cs. As of right now, the code looks like this:

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BookAPI.Models
{
  public class BookContext : DbContext
  {
    public BookContext(DbContextOPtions<BookContext> options)
        :base(options) // <-- error is pointing here
    {
        Database.EnsureCreated();
    }
  }
}

I am using Visual Studio 2019 free version on a Mac.

What am I missing and how do I fix it?

CodePudding user response:

try this

public class BookContext : DbContext
  {
    public BookContext(DbContextOptions<BookContext> options)
        :base(options) 
    {
       ....
    }
  }
  • Related