EF迁移用于通用Windows平台

5
我有以下DbContext,我想使用Entity Framework进行迁移。
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)
    {

    }

我执行了这个语句。
enable-migrations -ContextTypeName TestData.TestDbContext

在软件包管理器控制台中生成配置。但是由于以下命名空间/类找不到,因此生成出现编译错误:
using System.Data.Entity;
using System.Data.Entity.Migrations;
DbMigrationsConfiguration

.

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" }
            //    );
            //
        }
    }
}

有什么解决方案可以让配置编译通过,以便我可以添加迁移吗?
1个回答

2

这份EF7文档可能会对您有所帮助。

我进行了测试,DbContext应使用此引用:

using Microsoft.Data.Entity; 

using System.Data.Entity.Migrations;也应该更改为

using Microsoft.Data.Entity.Migrations;

谢谢您的回复。我尝试了那个方法,但是DbMigrationsConfiguration<TestData.TestDbContext>仍然找不到。 - Simon Angerbauer
是的,DbMigrationsConfiguration在EF7中不存在。但是有其他方法可以解决这个问题。这个链接可能会有所帮助。 - panda

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接