(Win7 x64、Visual Studio 2019、Entity Framework Core/SQLite/Tools v.5.0.2)
我遵循这个
https://docs.microsoft.com/ru-ru/ef/core/get-started/overview/first-app?tabs=visual-studio
实体框架核心教程。我复制/粘贴了所有代码以确保并使用 Nuget 控制台应用初始迁移。控制台根据日志报迁移成功:
PM> Update-Database
Build started...
Build succeeded.
Applying migration '20210121202929_InitialCreate'.
Done.
PM> Update-Database
Build started...
Build succeeded.
No migrations were applied. The database is already up to date.
Done.
PM>
尽管创建的数据库文件的文件图标表明可能存在问题:
我尝试运行教程中的主要代码,但出现错误
没有这样的表:博客
代码:
namespace EFCTest6
{
class Program
{
static void Main(string[] args)
{
using (var db = new BloggingContext())
{
// Create
Console.WriteLine("Inserting a new blog");
// ERROR! SqliteException: SQLite Error 1: 'no such table: Blogs'.
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
db.SaveChanges();
// Read
Console.WriteLine("Querying for a blog");
var blog = db.Blogs
.OrderBy(b => b.BlogId)
.First();
// Update
Console.WriteLine("Updating the blog and adding a post");
blog.Url = "https://devblogs.microsoft.com/dotnet";
blog.Posts.Add(
new Post
{
Title = "Hello World",
Content = "I wrote an app using EF Core!"
});
db.SaveChanges();
// Delete
Console.WriteLine("Delete the blog");
db.Remove(blog);
db.SaveChanges();
}
}
}
}
我还尝试将异常生成行从db.Add(...)
to更改为,db.Blogs.Add(...)
但它会生成相同的异常。