Adding new column to LINQ to SQL table
-
How can you update an Entity class when a new column in your db has been added? Column MyNewColumn has been added to MyPreviousTable. [System.Data.Linq.Mapping.DatabaseAttribute(Name="XXX")] public partial class XXXDataContext : System.Data.Linq.DataContext { // old code here old code old code old code etc... } [Table(Name="dbo.MyPreviousTable")] public partial class MyPreviousTable: INotifyPropertyChanging, INotifyPropertyChanged { // old code here old code old code old code etc... // new code here for MyNewColumn ??? ??? ??? etc... } Can you add code here b/c at top of generated file it says:
//------------------------------------------------------------------------------
// // This code was generated by a tool.
// Runtime Version:2.0.50727.3615
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------ -
How can you update an Entity class when a new column in your db has been added? Column MyNewColumn has been added to MyPreviousTable. [System.Data.Linq.Mapping.DatabaseAttribute(Name="XXX")] public partial class XXXDataContext : System.Data.Linq.DataContext { // old code here old code old code old code etc... } [Table(Name="dbo.MyPreviousTable")] public partial class MyPreviousTable: INotifyPropertyChanging, INotifyPropertyChanged { // old code here old code old code old code etc... // new code here for MyNewColumn ??? ??? ??? etc... } Can you add code here b/c at top of generated file it says:
//------------------------------------------------------------------------------
// // This code was generated by a tool.
// Runtime Version:2.0.50727.3615
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------Generally if the database is updated you would also update your entity map. However, the generated class is a partial class so you may be able to extend an create a partial class that adds the new columns. I haven't tried it, haven't had a reason to.
I know the language. I've read a book. - _Madmatt
-
Generally if the database is updated you would also update your entity map. However, the generated class is a partial class so you may be able to extend an create a partial class that adds the new columns. I haven't tried it, haven't had a reason to.
I know the language. I've read a book. - _Madmatt
Thanks for your response Mark.
-
How can you update an Entity class when a new column in your db has been added? Column MyNewColumn has been added to MyPreviousTable. [System.Data.Linq.Mapping.DatabaseAttribute(Name="XXX")] public partial class XXXDataContext : System.Data.Linq.DataContext { // old code here old code old code old code etc... } [Table(Name="dbo.MyPreviousTable")] public partial class MyPreviousTable: INotifyPropertyChanging, INotifyPropertyChanged { // old code here old code old code old code etc... // new code here for MyNewColumn ??? ??? ??? etc... } Can you add code here b/c at top of generated file it says:
//------------------------------------------------------------------------------
// // This code was generated by a tool.
// Runtime Version:2.0.50727.3615
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------Don't edit the generated file or you're setting yourself up for a lot of pain. If you toot in the wrong directly Visual Studio may regenerate the file on it's own. :laugh: If you haven't done any customization on your dbml file, it is relatively painless to delete the table and drag it back onto your designer. The new column is added automatically. You can also do it by adding the column manually to the designer and setting the appropriate properties; you would need to do this if you've customized your property/table names or set up custom relationships etc. After changing/updating the designer, and after you build again, the new column will be in the rest of your classes. Cheers.