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. Insert without primary key

Insert without primary key

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinq
5 Posts 3 Posters 0 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.
  • S Offline
    S Offline
    srinandan
    wrote on last edited by
    #1

    I am very new to the linq to sql getting proble when I am tryig to insert the record in a table as the table do not have any primary key. Thanks Sri...

    N 1 Reply Last reply
    0
    • S srinandan

      I am very new to the linq to sql getting proble when I am tryig to insert the record in a table as the table do not have any primary key. Thanks Sri...

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      What error are you getting? Are you aware that Linq to SQL is obsolte and Entity Framework is the successor?

      Best wishes, Navaneeth

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        What error are you getting? Are you aware that Linq to SQL is obsolte and Entity Framework is the successor?

        Best wishes, Navaneeth

        S Offline
        S Offline
        srinandan
        wrote on last edited by
        #3

        hi Navaneeth, thanks for making reply. I am getting following error "Can't perform Create, Update or Delete operations on 'Table(TestTable)' because it has no primary key. " Code is as follows:

        TestTable test = new TestTable();
        test.NAME = txtNametest.Text;
        test.ADDRESS = txtaddrtest.Text;
        db.GetTable<TestTable>().InsertOnSubmit(test);
        db.SubmitChanges();

        I google the problem but did not find any solution as per different forum we need to add a addition column (may identity) to set as primary key. but I don't think Its good practice to add extra column. Please suggest how should i go ahead. Thanks, Sri...

        A 1 Reply Last reply
        0
        • S srinandan

          hi Navaneeth, thanks for making reply. I am getting following error "Can't perform Create, Update or Delete operations on 'Table(TestTable)' because it has no primary key. " Code is as follows:

          TestTable test = new TestTable();
          test.NAME = txtNametest.Text;
          test.ADDRESS = txtaddrtest.Text;
          db.GetTable<TestTable>().InsertOnSubmit(test);
          db.SubmitChanges();

          I google the problem but did not find any solution as per different forum we need to add a addition column (may identity) to set as primary key. but I don't think Its good practice to add extra column. Please suggest how should i go ahead. Thanks, Sri...

          A Offline
          A Offline
          Andreas X
          wrote on last edited by
          #4

          just open the DBML-file in design mode and multi select the columns that you wand to set as primary key. for example NAME and ADDRESS. Then it will work! it is very NOT good practice to have tables i a database without a primary key!! kind regards

          Andreas Johansson
          IT Professional at Office IT Partner i Norrbotten Sweden
          What we don't know. We learn.
          What you don't know. We teach

          S 1 Reply Last reply
          0
          • A Andreas X

            just open the DBML-file in design mode and multi select the columns that you wand to set as primary key. for example NAME and ADDRESS. Then it will work! it is very NOT good practice to have tables i a database without a primary key!! kind regards

            Andreas Johansson
            IT Professional at Office IT Partner i Norrbotten Sweden
            What we don't know. We learn.
            What you don't know. We teach

            S Offline
            S Offline
            srinandan
            wrote on last edited by
            #5

            Thanks Andreas,:) Its working fine. its good, we can set the primary key on the entity level not in the database. thanks, Sri...

            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