'C# How to create a database using sqlite code-first?
I'm writing a .net console application and I'm trying to create a database using the code-first approach along with sqlite, but it doesn't get created. In all the tutorials that I found, the connection string was in the app.config file. But I don't have this file, so I chose the path that I found in the documentation.
Installed packages: EntityFramework. Microsoft.EntityFrameworkCore. Microsoft.EntityFrameworkCore.Sqlite Microsoft.EntityFrameworkCore.Tools
First, in the file manager console, I entered: EntityFrameworkCore\Add-Migration InitialCreate then: EntityFrameworkCore\Update-Database the console displayed that everything was successful, but I do not see the created database
Here I defined the user model:
public class User
{
public string UserId { get; set; }
public string AccessLevel { get; set;}
public string? Nickname { get; set; }
public string Name { get; set; }
public string Password { get; set; }
// Banned, normal, muted.
public string Status { get; set; }
public User(string name, string password, string status)
{
Name = name;
Password = password;
Status = status;
}
}
So I defined the context:
public class UsersContext : DbContext
{
public DbSet<User> Users { get; set; }
public UsersContext() { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(@"Data Source=.\SQLEXPRESS");
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
