当为UWP使用Scaffold-DbContext时,出现“无法加载DLL'sqlite3' [英] When using Scaffold-DbContext for UWP I get 'Unable to load DLL 'sqlite3''

查看:122
本文介绍了当为UWP使用Scaffold-DbContext时,出现“无法加载DLL'sqlite3'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Sqlite数据库中为UWP应用提供Entityframeworkcore DbContext。我这样做:

I am trying to scaffolf an Entityframeworkcore DbContext for a UWP app from a Sqlite databse. I do:

Scaffold-DbContext "data source=C:\SqliteDbFiles\Sqlite.db" Microsoft.EntityFrameworkCore.Sqlite

无论我如何尝试,尽管我一直收到此错误:

No matter what I try though I keep getting this error:

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)

任何帮助将不胜感激

推荐答案

在UWP上运行时使用的 sqlite3.dll 版本在设计时不起作用。您可以手动下载用于Windows的预编译二进制文件之一,然后将其复制到输出目录(例如 bin\x86\Debug ),然后再运行命令。

The version of sqlite3.dll used at runtime on UWP won't work at design-time. You can manually download one of the Precompiled Binaries for Windows and copy it to the output directory (e.g. bin\x86\Debug) before running the command.

一个更简单的解决方案是将 DbContext 在非UWP项目中,并在生成类后将其复制到UWP项目中。

A simpler solution might be to scaffold the DbContext in a non-UWP project and just copy the classes into the UWP project after they're generated.

这篇关于当为UWP使用Scaffold-DbContext时,出现“无法加载DLL'sqlite3'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆