myContext < /p>
Код: Выделить всё
internal class MyContext : DbContext
{
public DbSet Users { get; set; }
public string? DbPath { get; }
public MyContext()
{
var folder = Environment.SpecialFolder.Desktop;
var path = Environment.GetFolderPath(folder);
DbPath = Path.Join(path, "testcontext.db");
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Data Source={DbPath}");
}
}
< /code>
пользователь < /p>
internal class User
{
public int Id { get; set; }
public string Name { get; set; }
}
< /code>
Программа < /p>
MyContext myContext = new MyContext();
//User user = new User();
//user.Name = "bob";
//myContext.Users.Add(user);
//myContext.SaveChanges();
Подробнее здесь: https://stackoverflow.com/questions/797 ... t-instance
Мобильная версия