Home > Blockchain >  Why DbConnect is not found in Entity Framework Core
Why DbConnect is not found in Entity Framework Core

Time:12-22

I am working on a test web project using EF Core. I run into following problems when run test with DbContext.

Here are the info of my development environment:

  • ASP.NET Core 3.1
  • Entity Framework Core 3.1
  • IDE: Visual Studio 2019
  • Platform: Windows 10 PC

The main project name OdeToFood and a class library project OdeToFood.Data for data access using Entity Framework Core. I got the following error message when running following command:

C:\Projects\OdeToFood\OdeToFood.Data>dotnet ef dbcontext info -s ..\odetofood\odetofood.csproj

Build started...
Build succeeded.

Unable to create an object of type 'OdeToFoodDbContext'. For the different patterns supported at design time, see enter image description here

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

namespace WebApplication1.Data
{
    public class OdeToFoodDbContext : DbContext

    { 
        public OdeToFoodDbContext()
        {
        }

        public OdeToFoodDbContext(DbContextOptions options)
           : base(options)
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(@"...;");
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Restaurant>().ToTable("Restaurant");
        }
        public DbSet<Restaurant> Restaurats { get; set; }
    }
        public class Restaurant {
        [Key]
        public int Restaurats { get; set; }
    }
}
  • Related