Change EF database at design time RRS feed

  • Question

  • I'm very new to EF. I perceived it's promotion both online and personal as being back end independent, but I do not find that to be true. All examples I find, either you have to generate the database from EF or generate EF from the database.  That is disappointingly not database independent which to me would mean that my entity model could be applied to various databases of various architectures via the appropriate mappings. I found no explanations, tutorials, forum topics, or examples to support this. In fact, thus far, the best solution has been regeneration/migration of either the database or EF. This is highly inefficient.


    I have a product to sell and want to tout dynamic database connectivity as an advantage. Now, I can do all of this with my own objects, classes, and SQL the old fashioned way, but it would be immensely quicker and more effective and I could get to market 3 times quicker if I can do this through EF. So, I'm hoping that I'm just missing something.

    Forgive me for a lack of examples as I'm protecting my property and this is more a topic of design. But I will say it involves health care so forum participants can understand the magnitude of data that could be involved and why migration is in no way an option. Thanks.

    I would tremendously appreciate any guidance.

    Thursday, August 2, 2012 3:14 PM

All replies

  • Hi,

    It seems you mix several things here...

    The database independance you see mentioned is that you are able to abstract away the underlying database. So the same code could run against SQL Server or Oracle (in reality you likely have to establish best practice and test as the underlying features are not always the same regardless of the db).

    With mappings you could perhaps handle some schema differences for example if column names are not the same etc... At some point you are stuck if schema are different enough to just not be able to support your abstracted model. This is not something you'll do just for fun if you have some control over the db schema. Usually you'll use the same schema regardless of the actual underlying db.

    Not sure if by "dynamic" you meant also have the user to alter the db and have EF automagically deal with this change ?

    In short EF is to expose data as strongly typed objects to your code. My understanding is that your app have to work against a third party database schema you can't change and that you hoped to be able to use EF to map each of those schema to a single model used by your app ?

    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Thursday, August 2, 2012 4:27 PM
  • Im my opinion EF have it own advantages.

    With a few line codes it give me perfect results.

    It provides a "Data Source" for me and with that I can work with any kind of databases (oracle, sql,...) without I have to worrying of writing codes.

    Computer Enterprise Masoud Keshavarz for more information contact masoudk1990@yahoo.com

    Thursday, August 2, 2012 4:39 PM
  • dynamic means different table/name for same field. ie patient name being in a patient table or a person table. and the entity type having a patient name in a people table/type. the client db cannot change and neither can my entity types. but i have to either update my model or generate a cloent db from my model to attach the db. these options are all unacceptable, forcing me into workarounds to male entity effective.

    Friday, August 3, 2012 12:34 AM
  • If this is a table name, column name change you could perhaps use http://blogs.msdn.com/b/wriju/archive/2011/05/14/codefirst-ef-4-1-changing-database-table-and-column-name.aspx so that you can define a single model and have alternate mappings.

    If the db schema are different it's likely you'll be sometime stuck (for example a db that has a column to store a particular information but that another db doesn't have or just relations are not the same accross underlying products).

    You find no info about this because having a model mapped to several different underlying schema is not typical. (i.e. you try to create an app that can work on top of several third party database schemas ?)

    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Friday, August 3, 2012 8:20 AM
  • Thanks for the link, it helps...

    I can change a table name and field name during run-time. I can also set up for different databases during runtime also can't I?

    but we're getting off target. Being forced to either generate my model from the database or the database from my model is at the core of my issue with EF. If I can just connect my existing model to an existing database without any forced generation on either the database or my model's side, the rest can be handled.

    The only apparent way to do this is by using stored procedures to handle the mappings.

    Friday, August 3, 2012 12:28 PM
  • Hi ClarenceTunstall,

    Please refer to this article: http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx

    Scott Gu post a tutorial of Using EF code first with existing database, I hope this can help. : )

    Best Regards

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

    Monday, August 6, 2012 3:03 AM
  • Hi ClarenceTunstall,

    Have you solved the issue? I look forward to hearing from you. : )

    Best Regards

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

    Wednesday, August 15, 2012 1:47 AM