通用Windows平台的EF迁移

Sim*_*uer 5 c# entity-framework uwp

我有跟随DbContext,我想使用Entity Framwork迁移它

public class TestDbContext: DbContext
{
    public DbSet<State> States { get; set; }
    public DbSet<StateType> StateTypes { get; set; }
    public DbSet<Measure> Measures { get; set; }
    public DbSet<Priority> Priorities { get; set; }
    public DbSet<Task> Tasks { get; set; }
    public DbSet<TaskType> TaskTypes { get; set; }
    public DbSet<Document> Documents { get; set; }


    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        string databaseFilePath = "test.db";
        try
        {
            databaseFilePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, databaseFilePath);
        }
        catch (InvalidOperationException) { }
        optionsBuilder.UseSqlite($"Data source={databaseFilePath}");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {

    }
Run Code Online (Sandbox Code Playgroud)

我发表了声明

enable-migrations -ContextTypeName TestData.TestDbContext
Run Code Online (Sandbox Code Playgroud)

在程序包管理器控制台中生成配置.但是这一代有编译错误,因为无法找到以下命名空间/类:

using System.Data.Entity;
using System.Data.Entity.Migrations;
DbMigrationsConfiguration
Run Code Online (Sandbox Code Playgroud)

.

namespace TestData.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<TestDatas.TestDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(TestDatas.TestDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有关配置如何编译的任何解决方案,以便我可以添加迁移?

pan*_*nda 2

有关 EF7 的此文档可能会有所帮助。

我测试过,DbContext应该使用这个参考:

using Microsoft.Data.Entity; 
Run Code Online (Sandbox Code Playgroud)

并且using System.Data.Entity.Migrations;还应该改为

using Microsoft.Data.Entity.Migrations;
Run Code Online (Sandbox Code Playgroud)