2015-11-30 17 views
5

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?

Trả lời

2

Điều này documentation on EF7 có thể hữu ích.

tôi kiểm tra, DbContext nên sử dụng tài liệu tham khảo này:

using Microsoft.Data.Entity; 

using System.Data.Entity.Migrations; cũng nên thay đổi để

using Microsoft.Data.Entity.Migrations; 
+0

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

+0

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

+0

Cảm ơn bạn rất nhiều. – simsonimus

Các vấn đề liên quan