Reputation: 5260
I am trying dotnet core tutorial at https://learn.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc
TodoContext.cs
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();
}
}
}
So I got this "no overload method for UseInMemoryDatabase() takes 0 argument" I googled for UseInMemoryDatabase() method signature but could not find any.
What arguments should I provide to UseInMemoryDatabase()?
Update:
Once I downgrade Microsoft.EntityFrameworkCore.InMemory from 2.0.0-preview1-final to 1.1.1 and ran dotnet restore
the error disappeared.
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.1"/>
</ItemGroup>
I suspect the error is due to there is no "2.0.0-preview1-final" for Microsoft.EntityFrameworkCore.InMemory? If this is true then the error is not because of the number of argument but because InMemory db was is not installed and therefore UseInMemoryDatabase() was not defined anywhere in the project.
Upvotes: 3
Views: 5259
Reputation: 13
Install-Package Microsoft.EntityFrameworkCore.InMemory
This solved my problem
Upvotes: 1
Reputation: 19608
You need to give Database name.
services.AddDbContext<ApiContext>(options => options.UseInMemoryDatabase("RazorPagesApp"));
Upvotes: 16