存在问题的具体片段:
app.MapGet("/Person", (PersonDbContext context) =>
{
return context.Person.ToList();
})
.WithName("GetPersons")
.WithOpenApi();
app.MapPost("/Person", (Person person, PersonDbContext context) =>
{
context.Add(person);
context.SaveChanges();
})
.WithName("CreatePerson")
.WithOpenApi();
我想将 azure sql server 连接到我的项目。我启动了 React + .Net 项目,这些是我所做的唯一更改,但是我遇到了这个错误:
Error (active) CS1061 'RouteHandlerBuilder' does not contain a definition for 'WithOpenApi' and no accessible extension method 'WithOpenApi' accepting a first argument of type 'RouteHandlerBuilder' could be found (are you missing a using directive or an assembly reference?)
我遇到了这个文档,但它没有解决问题:https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs =netcore-cli
我对 azuresql 学习页面也有同样的问题。
我遵循 .NET CLI 步骤,为了让控制台应用程序连接到我的 azure sql 数据库,我从引用的 url 添加了两个 nuget、一个 using 和几行 swagger 行:
dotnet添加包Microsoft.AspNetCore.OpenApi dotnet 添加包 Swashbuckle.AspNetCore ...
using Microsoft.AspNetCore.OpenApi;
...
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
...
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
祝你好运
参考:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/openapi?view=aspnetcore-8.0