无法创建“RepositoryContext”类型的对象。有关设计时支持的不同模式,请参阅 https://go.microsoft.com/fwlink/?linkid=851728
using Microsoft.EntityFrameworkCore;
namespace StoreApp.Models
{
public class RepositoryContext : DbContext
{
public DbSet<Product> Products { get; set; }
public RepositoryContext(DbContextOptions<RepositoryContext> Options) : base(Options)
{
}
}
}
尝试直接配置连接字符串。
public class RepositoryContext : DbContext
{
public DbSet<Product> Products { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//Setup connectionstring directly
optionsBuilder.UseSqlServer("Data Source=(local);Initial Catalog = AhanoDB; Integrated Security = true");
}
}
你还需要
Services.AddDbContext<RepositoryContext>();