Tôi đã sau DbContext và tôi muốn di chuyển nó bằng cách sử Entity Cơ cấuEF Migration cho Universal Windows Platform
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)
{
}
tôi chạy báo cáo kết quả
enable-migrations -ContextTypeName TestData.TestDbContext
trong Package Manager Console để tạo ra các cấu hình. Nhưng thế hệ có lỗi biên dịch vì không thể tìm thấy các không gian tên/lớp sau:
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" }
// );
//
}
}
}
Bất kỳ giải pháp nào về cách cấu hình có thể biên dịch để tôi có thể thêm di chuyển?
Cảm ơn trả lời của bạn. Tôi đã thử điều đó. Nhưng DbMigrationsConfiguration vẫn không tìm thấy .. –
simsonimus
Có ~, DbMigrationsConfiguration không tồn tại trong EF7. Nhưng có cách khác để tiếp cận điều này. [This] (https://github.com/aspnet/EntityFramework/issues/629) có thể hữu ích. – panda
Cảm ơn bạn rất nhiều. – simsonimus