How to add data to a table using LINQ (EF 4.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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
Thanks AnnieMacD, Your guidance has been most helpful and I will get the book!
Mort
-
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
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
-
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
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