none
Maitaining Data Integrity with DB changes in 4.1 RRS feed

  • Question

  • I have been reading all over and don't see much for answers on how people are handling this with the Entity Framework(EF). Simply put, customer already have data that must be maintained. How are current EF users doing that? I am presuming from what I have seen that it is all or virtually all done manually.

    Specifically:

    What are you triggering off, DataBaseInitialize?

    Is there nothing in the EF to aid in detection of changes, or generation of ALTER TABLE SQL?

    In a previous C++ version of our product the table objects were self aware with a collection of fields. It could detect if the field wasn't there and add it, or run code to copy data from a renamed field into a new colum etc. No db versioning was necessary as each table had the info ot needed to generate the sql to bring it up to date. How are others handling this?

    Tuesday, November 22, 2011 7:19 PM

Answers

  • Hi,

    If you by 4.1 are talking about using DbContext and Code-First, Code-First doesn't yet have any builtin logic to update an existing database. And I am not aware of any plugins you can use to do this. You can however create your own initializer that you can plug in to your framework overriding IDatabaseInitializer, ssdl analyzing and db schema comparing.

    If you are using the EF modelling and Model-First you can by using plugins in "Entity Designer Database Generation Power Pack" generate SQL scripts that has the difference between an existing database and the new model by using the Generate Database from Model logic. However this pack is discontinued right now, but the current should still work.


    --Rune

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful" if the post helped you to a solution of your problem.
    Wednesday, November 23, 2011 7:02 AM
  • You may want to take a look at the Code First Migrations. Here is a link to a post talking the latest Alpha version: http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-released.aspx. There are a few more blog posts about migrations on this site (http://blogs.msdn.com/b/adonet/).

    Pawel

    Wednesday, November 30, 2011 1:36 AM

All replies

  • Hi,

    If you by 4.1 are talking about using DbContext and Code-First, Code-First doesn't yet have any builtin logic to update an existing database. And I am not aware of any plugins you can use to do this. You can however create your own initializer that you can plug in to your framework overriding IDatabaseInitializer, ssdl analyzing and db schema comparing.

    If you are using the EF modelling and Model-First you can by using plugins in "Entity Designer Database Generation Power Pack" generate SQL scripts that has the difference between an existing database and the new model by using the Generate Database from Model logic. However this pack is discontinued right now, but the current should still work.


    --Rune

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful" if the post helped you to a solution of your problem.
    Wednesday, November 23, 2011 7:02 AM
  • You may want to take a look at the Code First Migrations. Here is a link to a post talking the latest Alpha version: http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-released.aspx. There are a few more blog posts about migrations on this site (http://blogs.msdn.com/b/adonet/).

    Pawel

    Wednesday, November 30, 2011 1:36 AM