none
Using Entity framework for configurable database schema RRS feed

  • Question

  • I have a special requirement.

    We are creating a web based application using silverlight and WCF Data services. Our requirement is we should be able to change the database tables (insert some more field, or delete some fields or even we should be able to add some new tables). As far as I know EF generates the entity classes which is done at compile time. I heard there are some provision in EF 4.x

    Any solution would be appreciated.


    Senior Software Developer

    Wednesday, February 29, 2012 9:31 AM

Answers

  • Hi Javed937;

    To your statement, "insert some more field, or delete some fields or even we should be able to add some new tables", Entity Framework is a strongly typed framework and therefore this can only be done modifying the model as needed and recompiling the code and using migration available in Entity Framework 4.3.

    ADO.NET team blog You will find a couple of walkthrough's :

    EF 4.3 Code-Based Migrations Walkthrough
    EF 4.3 Automatic Migrations Walkthrough


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 29, 2012 1:45 PM

All replies

  • Hi Javed937;

    To your statement, "insert some more field, or delete some fields or even we should be able to add some new tables", Entity Framework is a strongly typed framework and therefore this can only be done modifying the model as needed and recompiling the code and using migration available in Entity Framework 4.3.

    ADO.NET team blog You will find a couple of walkthrough's :

    EF 4.3 Code-Based Migrations Walkthrough
    EF 4.3 Automatic Migrations Walkthrough


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 29, 2012 1:45 PM
  • Perhaps this SO thread (on the same topic) can be of help?

    http://stackoverflow.com/questions/4019895/modifying-an-entity-framework-model-at-run-time


     

       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4

    Friday, March 2, 2012 1:36 AM
  • Hi KristoferA,

    My requirement is reverse to the link which you have provided in the above link. What we want is for customization purpose no developer should be required to recompile the code. However the Schema and tables changes are allowed by a DB person. Some changes in to the configuration files like some xml files etc manually are also accepted. Our only concern is it should NOT require a recompilation of the client or service code.

     Also to make the thing clear, Database schema is not going to change at runtime. It will be changed even before the application is deployed (But without recompiling the code).


    Senior Software Developer

    Friday, March 2, 2012 4:07 AM
  • Hi KristoferA,

    Welcome to MSDN Forum.

    The only way to do migration in EF is @Fernando provided, but it needs recompilation.

    Best Regard


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us


    Monday, March 5, 2012 5:42 AM
    Moderator