recently i started to learn C# and ASP.NET Core for a new job, as part of the practice i created a small api for CRUD operation that includes a database, i have created the DB using the entity framework core. I wanted to figure out how does this DB created and all of the tables in it because in the code i did not mention any tables name or something.. ? and one more thing is can i access this DB using SSMS or some other GUI to actually see the data ? Note: I am using Visual Studio 2019
namespace TodoApi.Models
{
public class TodoContext : DbContext
{
public TodoContext(DbContextOptions<TodoContext> options)
: base(options)
{}
public DbSet<TodoItem> TodoItems { get; set; }
}
}
Startup.cs:
services.AddDbContext<TodoContext>(opt =>
opt.UseInMemoryDatabase("TodoList"));
Thank you in advance !
So, you're using an in-memory database. This means that's it's ultimately all stored in memory in the application. That means there will be no files on disk, and no way to access it remotely using a tool like SSMS. That's also why you don't need to specify a table name etc., because it's not needed for an in-memory database because it's kind of just a fancy way of storing all the data in an array, as a simple analogy. The in-memory provider's primary usage is for testing.
If you want to be able to view the contents of the database in a tool such as SSMS, you'll need to use the SQL Server provider (which will require a connection string etc.), which would be configured with opt.UseSqlServer(...). Alternatively if you didn't want to use SQL Server, you could use the SQLite provider.
Documentation about the different providers available can be found here.