Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Adding new column to LINQ to SQL table

Adding new column to LINQ to SQL table

Scheduled Pinned Locked Moved LINQ
databaseannouncementcsharplinqquestion
4 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrs999mrs999
    wrote on last edited by
    #1

    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.
    //
    //------------------------------------------------------------------------------

    N T 2 Replies Last reply
    0
    • M mrs999mrs999

      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.
      //
      //------------------------------------------------------------------------------

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • N Not Active

        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

        M Offline
        M Offline
        mrs999mrs999
        wrote on last edited by
        #3

        Thanks for your response Mark.

        1 Reply Last reply
        0
        • M mrs999mrs999

          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.
          //
          //------------------------------------------------------------------------------

          T Offline
          T Offline
          TheyCallMeMrJames
          wrote on last edited by
          #4

          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.

          They Call me Mister James

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups