none
Table<Object> --- > add column to object RRS feed

  • Question

  • Hi, is there a possibility to dynamically add a column to a table object ?? After changing an object (ie adding a column in the class) the table becomes unreadable (sqlexception "invalid column name"). Is there anyway around this, except for trashing the whole database and restarting from scratch ?????

    thx .... Steve

     

     

    Monday, January 9, 2012 7:39 PM

Answers

All replies

  • Hi StevieWright,

    Welcome to MSDN Forum.

    After dragging a table to your Linq to SQL designer, the class auto-generated is a partial class, so you can extend the class as what you want. Could you please how did you add the property and where the exception was thrown?

    Best Regards


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

    Wednesday, January 11, 2012 8:58 AM
    Moderator
  • Hi, extending the class is not my problem. My problem is that once I have extended the class (added, say a column by hand), SQL server, (or linq) refuses to read the table anymore, because there is a mismatch between the class and the table definition. This seems normal to me, but my question is: how do I programmatically update the table definition in SQL server, to include the new additions to the class in question ??.

    or: is there a way of programmatically deleting the table definition in SQL, and redefining a new empty table, which matches the additions I have made to the class ?

     

    thx ...   

    Sunday, January 15, 2012 1:18 PM
  • Hi StevieWright,

    Because the new property is exist in the model, but doesn't exist in the database, so there's no method to update the database. But you can recreate your database programmatically. Here's a link to tell you how to create database dynamically, please refer to it.

    http://msdn.microsoft.com/en-us/library/bb399420.aspx

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 16, 2012 3:18 AM
    Moderator