Tag Archives: Dotnet

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

The error above occurred while learning Entity Framework Core to use SQLite because the DB file could not be found.
Add the specific DB file path in UseSqlite(“”) : change to the following:

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; }
    }