问题描述
我的WPF程序正在使用带有SQLite数据库的Entity Framewok Core 3.1.1(代码优先).如果启动时不存在该数据库文件,则程序将调用 context.Database.Migrate()
创建一个.效果很好.
My WPF program is using Entity Framewok Core 3.1.1 (code-first) with a SQLite database. If the database file does not exist on startup, the program calls context.Database.Migrate()
to create one. Works great.
当我添加Costura.Fody(使用NuGet)时,大量的DLL消失了,该程序仍然有效-直到需要创建新的数据库文件为止.然后 Migrate()
函数失败,并显示错误:
When I added Costura.Fody (using NuGet), that huge collection of DLLs disappeared and the program still works - until it needs to create a new database file. Then the Migrate()
function fails with an error:
如果我尝试使用Package Manager Console手动添加迁移,则会遇到类似的问题-我得到
I have a similar issue if I try to use the Package Manager Console to add a migration manually - I get
删除Fody Costura软件包将使所有内容重新开始工作.我在SO或其他地方都没有找到任何涉及此问题的信息,而且Fody似乎很受欢迎,所以我必须做些愚蠢的事情,但我不知道在哪里看.
Removing the Fody Costura package causes everything to start working again. I haven't found anything on SO or elsewhere that references this issue, and Fody seems to be very popular, so I must be doing something dumb, but I don't know where to look.
有人知道如何让Fody Costura和EF Core迁移共存吗?
Does anyone know how to get Fody Costura and EF Core migrations to coexist?
非常感谢.
推荐答案
Sqlite作为嵌入式资源的表现不佳,没有任何调整.我知道在使用Costura.Fody作为文档中指定的时,这也是单元测试的常见问题.
Sqlite doesn't do well as an embedded resourse without a bit of tweaking. I know this is a common issue with Unit Tests as well when using Costura.Fody as specified in the docs.
对Weavers xml的简单调整应该可以解决此问题.看看嵌入Sqlite文件.
A simple adjustment of the Weavers xml should fix the issue though. Have a look at Embedding Sqlite Files.
这篇关于将Fody Costura与Entity Framework Core迁移结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!