Reputation: 52
I thought that I would learn to use ASP.NET Core, instead of what I am used to, ASP.NET, because Microsoft won't update ASP.NET anymore.
But I already got problems...
My problem is that I want to connect to my localdb file, and make this code-first table, but I get an error
No database provider has been configured for this DbContext.
even though I have a connection string for it:
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=api;Trusted_Connection=True;"
},
And I do include it in the startup, that it should use that connection string:
services.AddDbContext<UserContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
My table class is like this:
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Name { get; set; }
public int age { get; set; }
}
And here is my Context:
public class UserContext : DbContext
{
public DbSet<User> Users { get; set; }
}
Upvotes: 0
Views: 84
Reputation: 58
your UserContext should have public constructor which accepts a DbContextOptions and pass it to the base constructor .
Upvotes: 1