【发布时间】:2016-04-04 15:06:42
【问题描述】:
我目前正在尝试重新创建示例,在文档 http://ef.readthedocs.org/en/latest/getting-started/uwp.html 中完成,使用 EF7 和 SQLite 创建通用 Windows 平台应用程序。
我已经安装了所需的 EF7 和 EF7 命令包,并创建了模型和上下文:
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string dirPath = ApplicationData.Current.LocalFolder.Path;
string connectionString = "Filename=" + Path.Combine(dirPath, "blogging.db");
optionsBuilder.UseSqlite(connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
我现在的问题是,在构建解决方案之后,应该为我的模型创建初始表集的迁移脚手架命令失败,并出现以下异常:
PM> Add-Migration MyFirstMigration
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.Data.Entity.Design.Internal.StartupInvoker..ctor(String startupAssemblyName, String environment)
at Microsoft.Data.Entity.Design.DbContextOperations..ctor(ILoggerProvider loggerProvider, String assemblyName, String startupAssemblyName, String environment)
at Microsoft.Data.Entity.Design.MigrationsOperations..ctor(ILoggerProvider loggerProvider, String assemblyName, String startupAssemblyName, String environment, String projectDir, String rootNamespace)
at Microsoft.Data.Entity.Design.OperationExecutor.<>c__DisplayClass3_0.<.ctor>b__3()
at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
at Microsoft.Data.Entity.Design.OperationExecutor.<AddMigrationImpl>d__7.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
有没有人可以解决这个问题? 提前致谢
【问题讨论】:
-
您是否尝试过不指定完整路径名,例如您链接到的页面上的示例?
-
您的应用程序是否使用任何 Windows 运行时组件?您看到的错误与github.com/aspnet/EntityFramework/issues/3543 几乎相同
-
感谢您的回复@natemcmaster。它适用于普通的类库,但如果它与它不兼容,我如何在通用 Windows 应用程序中使用它?
-
EF 与 UWP 兼容。 WinRT 组件不同于 UWP 或 .NET 类库。
-
正如此处的答案之一 stackoverflow.com/questions/33526617/…> 所述,在 UWP 上,您似乎无法从命令运行迁移。您需要在应用程序中运行它们。但在我的情况下,这也不起作用,因为当我尝试访问它时,我得到表不存在的异常。
标签: sqlite win-universal-app entity-framework-core