0

I have been trying to use code first approach to create a database via already written models and context class. Below is my context class for reference.

using BankLibrary.Models;
using Microsoft.EntityFrameworkCore;

public class BankDBContext : DbContext
{
public BankDBContext()
{
}

public BankDBContext(DbContextOptions<BankDBContext> options) : base(options)
{
}

public DbSet<AccountHolderDetails> AccountDetails { get; set; }
public DbSet<TransactionDetails> TransactionDetails { get; set; }
public DbSet<LoanDetails> LoanDetails { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
   optionsBuilder.UseSqlServer("data source=(localdb)\\MSSQLLocalDB; database=BankDB;    integrated security=true");
}

}

But I have been getting the error: enter image description here

I don't know how to resolve it. I could not find any solution online. I have used this same code before for other projects but this time, I am getting the above error. Can anyone please help me with this?

I have already tried changes suggested by ChatGPT and reinstalled the packages (Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.SqlServer) as instructed. Still did not resolve the error.

2
  • Try to set context manually like Add-Migration Initial --context BankDBContext Commented Oct 18, 2024 at 10:35
  • Try to remove the empty constructor. I have had this issue in the past and it was the root cause of the error. Commented Nov 23, 2024 at 22:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.