0

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; }
}
1
  • I found out! You can use EF 6.3 and newer, instead of core, because they are crossplatform now. Commented Nov 20, 2020 at 17:27

1 Answer 1

1

your UserContext should have public constructor which accepts a DbContextOptions and pass it to the base constructor .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.