none
How to reload model at runtime? RRS feed

  • Question

  • Hi. Let's say that I have an application server that loads an EF model at startup. While it's running, we may make changes to the model and want our application to be able to reload the model rather than restarting the whole process. Assuming we know how to trigger the application, is there a way to reload an EF model at runtime?

    The functionlaity we're looking for is similar to how IIS reloads DLLs without shutting down. In fact, IIS is able seemlessly migrate to the new DLL without even dropping current requests. It would be ideal if our application could do the same thing, but with the EF model.

    Thanks.

    Thursday, June 9, 2011 1:02 AM

Answers

  • Hi,

    What darnold describes is how sync your entity model to the database schema, it doesn't reload your entity model in the application code (which I understood was your goal).

    AFAIK there isn't possible to reload the entity model once loaded the code for loading the model is far down in the ObjectContext logic and protected.

    What ASP.NET does is actually not reloading assemblies, it unloads the appdomain and reloads it (almost exactly the same as stop a process and start it again if it only has one appdomain).

    What I suspect, that what you want is only possible if you execute your entity model logic in a seperate appdomain.

    You can try to search on your favourite searchengine on .NET Reload AppDomain and check the out the results.

    Hope this helps!


    --Rune
    • Marked as answer by Barry Etter Friday, June 17, 2011 11:45 AM
    Thursday, June 9, 2011 6:04 AM

All replies

  • On 6/8/2011 9:02 PM, Barry Etter wrote:
    > Hi. Let's say that I have an application server that loads an EF model
    > at startup. While it's running, we may make changes to the model and
    > want our application to be able to reload the model rather than
    > restarting the whole process. Assuming we know how to trigger the
    > application, is there a way to reload an EF model at runtime?
    >
    > The functionlaity we're looking for is similar to how IIS reloads DLLs
    > without shutting down. In fact, IIS is able seemlessly migrate to the
    > new DLL without even dropping current requests. It would be ideal if our
    > application could do the same thing, but with the EF model.
    >
     I know I used these statements at a page-load, because the model changed
    and the schema was out of sync.
     
    Database.SetInitializer<ProductCatalog>(new
    RecreateDatabaseIfModelChanges<ProductCatalog>());
     
    But it requires one to be using CPT.
     
     
    Thursday, June 9, 2011 1:35 AM
  • Hi,

    What darnold describes is how sync your entity model to the database schema, it doesn't reload your entity model in the application code (which I understood was your goal).

    AFAIK there isn't possible to reload the entity model once loaded the code for loading the model is far down in the ObjectContext logic and protected.

    What ASP.NET does is actually not reloading assemblies, it unloads the appdomain and reloads it (almost exactly the same as stop a process and start it again if it only has one appdomain).

    What I suspect, that what you want is only possible if you execute your entity model logic in a seperate appdomain.

    You can try to search on your favourite searchengine on .NET Reload AppDomain and check the out the results.

    Hope this helps!


    --Rune
    • Marked as answer by Barry Etter Friday, June 17, 2011 11:45 AM
    Thursday, June 9, 2011 6:04 AM
  • Hi Barry,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 17, 2011 3:34 AM
    Moderator
  • Alan, I marked Rune's post as the answer to my question.

     

    Thanks.

    Friday, June 17, 2011 11:46 AM