Database migrations for Entity Framework 4

前端 未结 5 1549
面向向阳花
面向向阳花 2020-12-14 04:06

I\'ve been playing with Entity Framework 4, using the model driven approach to generate the database script from my entities. This is great but I\'m not sure how this works

5条回答
  •  温柔的废话
    2020-12-14 04:37

    I'm working on an alternative to EF.Migrations library - EntityFramework.SchemaCompare. It allows to physically compare a db schema with an entities model representing database context (EF.Migrations doesn't do it). This can be fired either during database initialization or manually on request. Consider the following example

    #if DEBUG
    Database.SetInitializer(new CheckCompatibilityWithModel());
    #endif
    

    It will throw an exception during database initialization describing the differences between db schema and model if incompatibility issues are found. Alternatively you can find those differences at any time in your code this way

    using (var ctx = new DatabaseContext())
    {
        var issues = ctx.Database.FindCompatibilityIssues();
    }
    

    Then having those differences / incompatibility issues on hands you can either update the db schema or the model.

    This approach is particularly useful when you need complete control over the database schema and model design and/or working in a team where multiple team members are working on the same db schema and model. It can also be used in addition to EF.Migrations.

    Fork me at GitHub: https://github.com/kriasoft/data

提交回复
热议问题