- 添加NuGet包:Microsoft.EntityFrameworkCore.Sqlite
- 添加DataModel
public class ResourceMessage
{
[Key]//主键
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] //设置自增
public string Id { get; set; }
public string? OtherKey { get; set; }
}
3.添加DbContext
public class DataModel_Test : DbContext
{
public DbSet<ResourceMessage> ResourceMessages { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Data Source=Test.db");
}
}
发表回复