YUN
学习工作赚钱对象是正事
学习编程技术

WPF使用SqlLite数据库(EF版本)

  1. 添加NuGet包:Microsoft.EntityFrameworkCore.Sqlite
  2. 添加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");
      }
  }

发表回复

textsms
account_circle
email

学习编程技术

WPF使用SqlLite数据库(EF版本)
添加NuGet包:Microsoft.EntityFrameworkCore.Sqlite 添加DataModel public class ResourceMessage { [Key]//主键 [DatabaseGenerated(DatabaseGeneratedOption.Identity)]…
扫描二维码继续阅读
2024-11-20