entity framework core + SQLite Error 1: 'no such table: Blogs'.

在学习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; }
    }
发布了122 篇原创文章 · 获赞 21 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/xingkongtianyuzhao/article/details/103366744
今日推荐