我想在https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vscDOTNET核心的UseInMemoryDatabase沒有重載方法()接受0參數
TodoContext.cs DOTNET核心教程
using Microsoft.EntityFrameworkCore;
namespace TodoApi.Models
{
public class TodoContext : DbContext
{
public TodoContext(DbContextOptions<TodoContext> options)
: base(options)
{
}
public DbSet<TodoItem> TodoItems { get; set; }
}
}
Startup.cs
using ...
using TodoApi.Models;
using Microsoft.EntityFrameworkCore;
namespace TodoApi
{
public class Startup
{
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.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase());
services.AddMvc();
services.AddScoped<ITodoRepository, TodoRepository>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMvc();
}
}
}
所以我就這個「UseInMemoryDatabase()的無重載方法需要0參數」 我搜索UseInMemoryDatabase()方法簽名,但找不到任何。
我應該向UseInMemoryDatabase()提供哪些參數?
更新:
一旦我降級Microsoft.EntityFrameworkCore.InMemory從2.0.0-preview1決賽1.1.1跑dotnet restore
錯誤消失。
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1"/>
</ItemGroup>
我懷疑的錯誤是由於沒有「2.0.0 preview1決賽」爲Microsoft.EntityFrameworkCore.InMemory?如果這是真的,那麼錯誤不是因爲參數的數量,而是因爲InMemory數據庫沒有安裝,因此UseInMemoryDatabase()沒有在項目中的任何位置定義。
如果使用ide的「定義」功能,該怎麼辦? – zerkms
vscode說「找不到定義」 – Shawn
我相信這是在這裏定義的https://github.com/aspnet/EntityFramework/blob/dev/src/EFCore.InMemory/Extensions/InMemoryDbContextOptionsExtensions.cs – zerkms