1

Im trying to create a my tables in my sql database using the code first approach and im getting the "No DbContext was found in assembly 'LibrarySystem'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic." error in the package manager console

I have tried several different solutions for example the one shown in Migration: No DbContext was found in assembly

this is my Context class where im using dbcontext

using System.Collections.Generic;
using System.Text;
using IDataInterface;
using Microsoft.EntityFrameworkCore;

namespace DataAccess
{
    public class LibraryContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server = localhost; Database = Library; Trusted_connection = true");
        }
        public DbSet<Book> Books { get; set; }
        public DbSet<Shelf> Shelves { get; set; }
    }
}
Wing
  • 11
  • 1
  • 2
  • Are you working with multiple projects in a solution? – Muhammad Hannan Nov 02 '19 at 17:03
  • Yes i was using multiple projects in my solution – Wing Nov 02 '19 at 17:27
  • When you need to target different project from default, try to run migrations commands with --project your.project.name parameter as described in [docs](https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#target-and-startup-project) – Pietro Nov 02 '19 at 20:53

1 Answers1

0

I found the solution to the problem. Since i was using multiple projects DataInterface, DataAccess, LibrarySystem and UnitTests this is where the problem hid. The way to fix it was to change the default project to DataAccess instead of one of the other ones. The issue i had a hard time seeing was that i was trying to update the database from a default project that did not have DbContext in it.

Wing
  • 11
  • 1
  • 2