【问题标题】:Add-Migration command not working error 0x80073D54添加迁移命令不起作用错误 0x80073D54
【发布时间】:2016-09-12 14:04:24
【问题描述】:

我通过https://blogs.windows.com/buildingapps/2016/05/03/data-access-in-universal-windows-platform-uwp-apps/#LTm66jG1JvVVXDxi.97创建了一个应用程序

但是命令 Add-Migration MyFirstMigration 不起作用。 你知道为什么

PM> Add-Migration MyFirstMigration
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: **The process does not contain the identity of the package (Exception from HRESULT: 0x80073D54)**
   at Windows.Storage.ApplicationData.get_Current()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Data.Sqlite.SqliteConnection.GetApplicationData()
   at Microsoft.Data.Sqlite.SqliteConnection.AdjustForRelativeDirectory(String path)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
   at Microsoft.Data.Entity.Storage.Internal.SqliteRelationalConnection.Open()
   at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.Execute[T](IRelationalConnection connection, Func`3 action, String executeMethod, Boolean openConnection, Boolean closeConnection)
   at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.ExecuteScalar(IRelationalConnection connection, Boolean manageConnection)
   at Microsoft.Data.Entity.Storage.Internal.SqliteDatabaseCreator.HasTables()
   at Microsoft.Data.Entity.Storage.RelationalDatabaseCreator.EnsureCreated()
   at Microsoft.Data.Entity.Infrastructure.DatabaseFacade.EnsureCreated()

【问题讨论】:

    标签: c# entity-framework migration uwp


    【解决方案1】:

    我无法重现您的问题。我的环境信息如下:Visual Studio 2015 update 3, windows 10 SDK 14393, UWP target version 14393,min version 10586。

    但是根据您的异常堆栈详细信息,Windows.Storage.ApplicationData.get_Current() 发生了错误。 Add-Migration 操作似乎要访问您应用的本地文件夹,但由于该应用尚未部署,因此当前没有本地文件夹。

    Add-Migration 将实例化您的DbContext 类,该类检索Windows.Storage.ApplicationData.Current.LocalFolder.Path 的值以构建连接字符串。由于它是从 VS 调用的,因此它似乎由于缺少在 Windows Store 应用程序上下文中运行时提供的包标识符而失败。

    所以请尝试部署您的应用程序或先运行它以确保本地文件夹存在。如果本地文件夹已经创建,但异常仍然存在,您可以像下面这样硬编码详细连接字符串,而不是只有一个 DB 文件名Sensors.db(OnConfiguring 方法在模型类中)。以下代码中的文件夹名称61bbd292-ef8c-4a2e-b0c4-360dd2335d4d_9889v3km7snsp是您应用的包家族名称,您可以在Package.mainfest->Packaging中找到。

     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
     {
         var connection = @"Filename=C:\Users\YourUserName\AppData\Local\Packages\61bbd292-ef8c-4a2e-b0c4-360dd2335d4d_9889v3km7snsp\LocalState\Sensors.db";
         optionsBuilder.UseSqlite(connection);
     }
    

    更多详情请参考Entity Frameworkissue1058第7楼。

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 2017-05-15
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多