在学习Entity Framework Core使用SQLite时,出现上述错误,原因是找不到db文件.

在UseSqlite("")中添加具体的db文件路径:改成如下即可:

protected override void OnConfiguring(DbContextOptionsBuilder options)
            => options.UseSqlite(@"Data Source=E:\alexander\code\sqlite\EFGetStarted\blogging.db");

 

    public class BloggingContext : DbContext
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder options)
            => options.UseSqlite(@"Data Source=blogging.db");
    }

    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }

        public List<Post> Posts { get; } = new List<Post>();
    }

    public class Post
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }

        public int BlogId { get; set; }
        public Blog Blog { get; set; }
    }

 

相关文章:

  • 2021-08-10
  • 2021-08-07
  • 2021-08-23
  • 2022-12-23
  • 2021-11-14
  • 2021-09-26
  • 2022-01-16
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-10-28
相关资源
相似解决方案