5
我有以下的DbContext,我想使用實體FramworkEF遷移通用的Windows平臺
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
在Package Manager控制檯生成配置。 但一代有編譯錯誤,因爲下面的命名空間/類不能找到:
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" }
// );
//
}
}
}
有關配置如何編譯的任何解決方案,以便我可以添加遷移?
感謝您的答覆。我試過了。但是DbMigrationsConfiguration仍然沒有找到.. –
simsonimus
是的,DbMigrationsConfiguration在EF7中不存在。但還有其他方法可以解決這個問題。 [This](https://github.com/aspnet/EntityFramework/issues/629)可能會有所幫助。 – panda
非常感謝。 – simsonimus