【发布时间】:2020-02-15 13:54:22
【问题描述】:
我有一个 .Net Core 2.2 应用程序,我进行了迁移并成功更新了数据库,我想使用 Entity Framework Core 添加一个带有动作的 API 控制器,但它不会成功搭建。在此之前我做了一个类似的应用程序,它生成的控制器很好,我不确定问题是什么,我尝试自己解决它,但找不到解决方案。
在包控制台我得到这个信息:
无法识别的选项'--useSqlite' 在 Microsoft.Extensions.CommandLineUtils.CommandLineApplication.HandleUnexpectedArg(CommandLineApplication 命令,字符串 [] args,Int32 索引,字符串 argTypeName) 在 Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 在 Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args) 在 Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
我已尝试卸载 sqlite NuGetpackage,但仍然出现错误,我尝试重新构建应用程序并重新启动 Visual Code,但它仍然无法正常工作。
这是我的文件
Startup.cs
{
public Startup(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().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddDbContext<LoanContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DevConnection")));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
}
}
appsetting.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"connectionStrings": {
"DevConnection": "server=(local)\\sqlite;Database=TestDB;User Id=sa;Password=LovelyWorld1;"
}
}
贷款.cs
public class Loan
{
[Key]
public int Details { get; set; }
[Column(TypeName = "nvarchar(250)")]
[Required]
public string LoanID { get; set; }
[Column(TypeName = "nvarchar(10)")]
public string BorrowerName { get; set; }
[Column(TypeName = "nvarchar(100)")]
public string FundingAmount { get; set; }
[Column(TypeName = "nvarchar(100)")]
public string RepaymentAmount { get; set; }
}
}
【问题讨论】:
-
您似乎在使用 SQLite,但连接字符串适用于 SQL Server 等数据库服务器。你有这个项目在 GitHub 上还是我可以查到的地方?
标签: c# visual-studio api .net-core controller