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. How to add data to a table using LINQ (EF 4.1)

How to add data to a table using LINQ (EF 4.1)

Scheduled Pinned Locked Moved LINQ
tutorialcsharpdatabaselinqannouncement
8 Posts 3 Posters 9 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
    Mort Strom
    wrote on last edited by
    #1

    I'm using Entity Framework 4.1 and have constructed my first LINQ query shown here

            using (var context = new MyDBEntities())
            {
                var y = (from t in context.MyDbTable
                                  where t.Field3 == true
                                  orderby t.Field1 ascending
                                  select new { t.Field0, t.Field1, t.Field2, t.Field3 }
                                  );
                foreach (var x in y)
                {
    		/\* doing something \*/
                }
            }
    

    My query works as expected and now in a similar way using LINQ I need to "insert" or "add" data to my table. I'm looking for an online resource or a psuedo example, using LINQ, to add a record and update a record in a table. I've searched on "insert"/"update" but these words don't appear to be part of the LINQ lexicon. Thanks for any direction on using LINQ to insert and update data on a table -- i don't know where to begin.

    Mort

    L 2 Replies Last reply
    0
    • M Mort Strom

      I'm using Entity Framework 4.1 and have constructed my first LINQ query shown here

              using (var context = new MyDBEntities())
              {
                  var y = (from t in context.MyDbTable
                                    where t.Field3 == true
                                    orderby t.Field1 ascending
                                    select new { t.Field0, t.Field1, t.Field2, t.Field3 }
                                    );
                  foreach (var x in y)
                  {
      		/\* doing something \*/
                  }
              }
      

      My query works as expected and now in a similar way using LINQ I need to "insert" or "add" data to my table. I'm looking for an online resource or a psuedo example, using LINQ, to add a record and update a record in a table. I've searched on "insert"/"update" but these words don't appear to be part of the LINQ lexicon. Thanks for any direction on using LINQ to insert and update data on a table -- i don't know where to begin.

      Mort

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      If you do a search on Entity Framework AddObject and SaveChanges, you will gets lots of information and examples. I recommend LinqPad for testing out your queries, see here http://www.linqpad.net/[^].

      It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

      P 1 Reply Last reply
      0
      • L Lost User

        If you do a search on Entity Framework AddObject and SaveChanges, you will gets lots of information and examples. I recommend LinqPad for testing out your queries, see here http://www.linqpad.net/[^].

        It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        It's good to see you back Annie. How are you doing?

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        L 1 Reply Last reply
        0
        • P Pete OHanlon

          It's good to see you back Annie. How are you doing?

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I'm doing great and v. busy. I'm in the middle of testing a prototype version of my new software hopefully starting to install in August. I switched from VB to C# in March and rewrote all my code although I have kept a few VB libraries! I have a lot of learning to do as well as being architect, designer, DBer, coder, installer, supporting old s/w, running the business... I'm a one-person shop! That's why you don't see much of me but I'll be back next year. Thanks for asking. :rose:

          It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

          P 1 Reply Last reply
          0
          • M Mort Strom

            I'm using Entity Framework 4.1 and have constructed my first LINQ query shown here

                    using (var context = new MyDBEntities())
                    {
                        var y = (from t in context.MyDbTable
                                          where t.Field3 == true
                                          orderby t.Field1 ascending
                                          select new { t.Field0, t.Field1, t.Field2, t.Field3 }
                                          );
                        foreach (var x in y)
                        {
            		/\* doing something \*/
                        }
                    }
            

            My query works as expected and now in a similar way using LINQ I need to "insert" or "add" data to my table. I'm looking for an online resource or a psuedo example, using LINQ, to add a record and update a record in a table. I've searched on "insert"/"update" but these words don't appear to be part of the LINQ lexicon. Thanks for any direction on using LINQ to insert and update data on a table -- i don't know where to begin.

            Mort

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Additionally, if you really want to understand EF, I recommend Julia Lerman's book "Programming Entity Framework". It was published before 4.1 was released (so no Code First) but covers 4.0 in the Second Edition. I have all the EF books (I believe) and it is by far the best one IMHO.

            It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

            M 1 Reply Last reply
            0
            • L Lost User

              Additionally, if you really want to understand EF, I recommend Julia Lerman's book "Programming Entity Framework". It was published before 4.1 was released (so no Code First) but covers 4.0 in the Second Edition. I have all the EF books (I believe) and it is by far the best one IMHO.

              It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

              M Offline
              M Offline
              Mort Strom
              wrote on last edited by
              #6

              Thanks AnnieMacD, Your guidance has been most helpful and I will get the book!

              Mort

              1 Reply Last reply
              0
              • L Lost User

                I'm doing great and v. busy. I'm in the middle of testing a prototype version of my new software hopefully starting to install in August. I switched from VB to C# in March and rewrote all my code although I have kept a few VB libraries! I have a lot of learning to do as well as being architect, designer, DBer, coder, installer, supporting old s/w, running the business... I'm a one-person shop! That's why you don't see much of me but I'll be back next year. Thanks for asking. :rose:

                It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Where abouts are you at now?

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                L 1 Reply Last reply
                0
                • P Pete OHanlon

                  Where abouts are you at now?

                  Forgive your enemies - it messes with their heads

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I'm up in Applecross on the west coast. It's a small peninsula opposite Skye but on the mainland. If you Google "Applecross Pass" you'll see the road. Oh, Google is real cool today!:cool:

                  It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                  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