我正在尝试从Sqlite数据库中为一个UWP应用程序提供一个Entityframeworkcore DbContext。我这样做:
Scaffold-DbContext "data source=C:\SqliteDbFiles\Sqlite.db" Microsoft.EntityFrameworkCore.Sqlite
无论我尝试什么,我都会遇到这个错误:
System.DllNotFoundException: Unable to load DLL 'sqlite3': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)
at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
at Microsoft.Data.Sqlite.SqliteConnection.Open()
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ReverseEngineerImpl>d__21.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to load DLL 'sqlite3': This operation is only valid in the context of an app container. (Exception from HRESULT: 0x8007109A)
非常感谢任何帮助
答案 0 :(得分:3)
UWP在运行时使用的sqlite3.dll
版本在设计时无法使用。在运行命令之前,您可以手动下载其中一个Precompiled Binaries for Windows并将其复制到输出目录(例如bin\x86\Debug
)。
一个更简单的解决方案可能是在非UWP项目中搭建DbContext
,并在生成后将这些类复制到UWP项目中。