Wednesday 15 August 2012

entity framework - About Dependency Injection, IRepository and EF Migrations scenarios -


How am I confused about how the EF migration handles scenarios where my treasures are generic ( IRAPSignatory & lt; & Gt; ) and my selected dependency injector tool is injected in runtime, you know that the database has been updated / synchronized by migration using three elements:

  1. Database model (object context and dbst & gt; c
  2. Migration Clause
  3. In the Migration Database already exists (if any)

    You can see that the original element object context And its properties are if you expose an object project without a DBSAT property, then the process used by the migration is not executed properly.

    I have my solution with the following projects: Core.NTT, Core. Repository Interfaces and Infrastructure Repository EF, Infraestructure.DependencyResolution, and UI.WebSite.

    As you know, the repository is injected when the Works constructor is required:

      Private IRPorporation & lt; Products & gt; _productrepo; Public Test (IRPoZetry & lt; Products & gt; Product Repo) {_productRepo = productrepo; }   

    The question is how can migration be updated in the database because there is no DBSet in my object context & lt; & Gt; Properties (Injecting those repositories into my dependency tools runtime)?

    Thank you for your valuable assistance.

    I think the code first migration can not update your model If you have an empty dbcontext object (I mean without dbSet properties), so there is a way to handle this scenario where you are using the repository pattern and injected dbcontext objet into each requested repository:

    Design two dbcontext objects, for development time (devdbcontext) For A and other production environments (proddbcontext).

    1. DehDBanktext will be designed with DBST properties, thus migration workflow will be normal during the migration time; This model will detect changes and reproduce the database etc. When you are in DEBUG mode (#if DEBUG)

    2. Proddbcontext will be a derived DBnettext object without the DBST property and when you are in release mode (#IfRelage) . To update the production database, I will create a database script and set the database initilizer to be set to Null.

      What do you think about this solution?

No comments:

Post a Comment