【发布时间】:2020-11-23 02:39:59
【问题描述】:
我做的第一件事是去appsettings.json然后我写了那个代码:
"ConnectionStrings": {
"LibraryConnection": "Server=(localdb)\\MSSQLLocalDB;DataBase=Library_Dev;Trusted_Connection=True;MultipleActiveResultSets=True"
}
接下来我使用 (using Microsoft.EntityFrameworkCore; (DbContext)) 添加了这个类:
public class LibraryContext : DbContext
{
public LibraryContext(DbContextOptions options) : base(options) { }
DbSet<Person> person { get; set; }
}
Person 类有属性但忽略它。
然后我打开Startup.cs并在ConfigureServices方法中添加:
services.AddDbContext<LibraryContext>(
options => options.UseSqlServer(
Configuration.GetConnectionString("LibraryConnection")));
当然我输入了控制台管理包:
add-migration "Initial migration"
但我在 SQL Server 对象资源管理器中看不到 Library_Dev。
如果你能帮助我,我将非常感激。
【问题讨论】:
标签: c# asp.net .net sql-server localdb