none
if i change the schema of a database,for example,add a new column to a datatable, must i recompile the dbml ? can i form the datacontext dynamically by code at runtime? RRS feed

  • Question

  • if i change the schema of a database,for example,add a new column to a datatable, must i recompile the dbml ? can i form the datacontext dynamically by code at runtime?
    Saturday, July 3, 2010 5:37 AM

Answers

  • While you could query the database schema yourself and emit an XML mapping instead of DBML at runtime what would you map the new field too?

    Your class wouldn't have the property unless you code generated that too at runtime.

    Even after all that... your program wouldn't have any references to the new runtime field so it wouldn't display on the screen, validate, be used in calculations etc. unless you changed it to use reflection.

    Basically you'd be fighting LINQ all the way - if you really need this it's a case where the older ADO.NET technologies that are late-bound such as DataSet is a much better choice.

    [)amien

    • Marked as answer by ValorZ Sunday, July 4, 2010 3:42 AM
    Saturday, July 3, 2010 2:38 PM
    Moderator

All replies

  • While you could query the database schema yourself and emit an XML mapping instead of DBML at runtime what would you map the new field too?

    Your class wouldn't have the property unless you code generated that too at runtime.

    Even after all that... your program wouldn't have any references to the new runtime field so it wouldn't display on the screen, validate, be used in calculations etc. unless you changed it to use reflection.

    Basically you'd be fighting LINQ all the way - if you really need this it's a case where the older ADO.NET technologies that are late-bound such as DataSet is a much better choice.

    [)amien

    • Marked as answer by ValorZ Sunday, July 4, 2010 3:42 AM
    Saturday, July 3, 2010 2:38 PM
    Moderator
  • thanks for you replying.

    i know that the dataset can do that,but i am now working on a silverlight project,and the silverlight do not support dataset.

     

    Sunday, July 4, 2010 3:42 AM