我在使用.NET Core 2.0的MAC上
我的program.cs
文件设置了我的机器上开发的环境集
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
//.UseStartup<Startup>()
.UseStartup("MoviesLibfrary")
.Build();
我有一个名为StartupDevelopment
的新课程:
public class StartupDevelopment
{
public StartupDevelopment(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<MvcTriviaContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("MvcTriviaContext")));
}
}
调试应用程序确实使用StartupDevelopment
类。
使用dotnet ef migrations add InitialCreate
和dotnet ef database update
正在尝试使用SQL Server。
运行数据库升级时遇到的错误
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:TCP提供者,错误:25 - 连接字符串无效)
appsettings.Development.json
中的连接字符串:
"ConnectionStrings": {
"MvcTriviaContext": "Data Source=Data\\databasename.db"
}
如何将dotnet ef
用于sqlite,因为我的开发环境被指定为使用sqlite?