Page view counter

How Do I: LINQ to SQL: Updating the Database

In this video I demonstrated how to create, update and delete records through LINQ, simple transactions, updates across relationships, and custom column and row validation.

Presented by Scott Stanfield

Duration: 17 minutes, 16 seconds

Date: 15 November 2007

Watch the video   |   Download the video   |   Get the code

Video downloads: WMV | Zune | iPod | PSP | MPEG-4 | 3GP

Audio downloads: AAC | WMA | MPEG-4 | MPEG-2

Comments : 23

Leave a Comment

ShaunO : On March 26, 2008 10:11 PM said:

Nice video, bonus with your kid walking in asking to use your computer :D!

ramah : On March 27, 2008 4:53 AM said:

nice video. thank you

rtisserand : On March 27, 2008 10:56 AM said:

Would it be possible to get a VB version of this video?

dotNetNewbie : On April 21, 2008 6:11 AM said:

Hi Scott,

Thank you for your great video. I'm following each one of them to start learning Linq.

In this video here, when you extend the class Order(public partial class Order) the intellisense doesn't work, and the namespace System.Data.Linq.ChangeAction is not recognized. It compiles right but qhen i run the project gives the following error message:

CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

However, in the NorthWind.designer.cs the method recognizes the namespace...

partial void OnValidate(System.Data.Linq.ChangeAction action);

Can you tell me of something is missing?

Best regards,

Manuel

kteepl : On June 06, 2008 11:24 AM said:

VB PLEASE!!

McGuire : On June 06, 2008 5:50 PM said:

I agree.  Will the next several be done in VB at some point?

vasireddybharath : On June 23, 2008 10:28 PM said:

This is very nice to have. Its just like readymade....

Good stufffffffffffff......

Thnks

Bharath Reddy VasiReddy

satishnarni : On July 24, 2008 5:56 AM said:
satishnarni : On July 30, 2008 7:40 AM said:

this is nice

http;//mysearchyard.googlepages.com

cv_vikram : On August 14, 2008 6:26 PM said:

thanks....

djdenni : On August 19, 2008 6:20 PM said:

Does anybody know how to convert the following code to VB?

var r = from p in db.Products

       where p.UnitPrice > 15 &&

       p.Order_Details.Sum(x => x.Quantity) < 200

       select p;

Thanks, Dave

S.Pirashanth : On August 28, 2008 3:00 AM said:

Many thanks for the great videos

D' Polygon : On September 11, 2008 7:25 PM said:

Hello I would really be happy to have this video in VB pls!!!

Thanks so much for the videos you shared.

vpmragu : On September 22, 2008 9:07 AM said:

thank you so much for this video.

senfo : On September 22, 2008 7:02 PM said:

So I didn't really like this one (no offense).  That wasn't a very common update scenario.  How about something a little more common?  For example, open a Product in an Edit page and UPDATE any changes in the database.

sameeralibhai : On October 03, 2008 2:45 PM said:

That was hilarious (at the end!!) :) Those of us who have kids know how that feels

gatehyperion : On October 07, 2008 3:15 PM said:

Excellent video!  Nice added touch with the sql profiling and perfect comic relief at the end! That was just too dang funny! Since you have that cool voice can you say "I am your father luke" at the end of your next video?

ASeventhSign : On October 09, 2008 4:26 PM said:

Love the video...

When the example tried to delete the 'lame' products, I get an Exception:

The DELETE statement conflicted with the REFERENCE constraint "FK_Order_Details_Products". The conflict occurred in database "Northwind", table "dbo.Order Details", column 'ProductID'.

The statement has been terminated.

PietS : On October 14, 2008 6:33 AM said:

I had the same problem as ASeventhSign.

Did we do something wrong? :S

radu_m : On October 20, 2008 9:48 PM said:

This VB Code worked fine for me, i'm showing the TransactionScope to but if you want to have your changes permanently than remove TransactionScope wrapper.

Protected Sub btLame_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btLame.Click

       Using ts As Transactions.TransactionScope = New Transactions.TransactionScope()

           Dim NW As New NorthwindDataContext

           Dim r = From p In NW.Products _

                   Where p.UnitPrice > 15 And _

                   (Aggregate ordQunat In p.Order_Details _

                   Into Sum(ordQunat.Quantity)) < 200

           For Each p As Product In r

               p.ReorderLevel = 0

           Next

           NW.SubmitChanges()

           GridView1.DataSource = r

           GridView1.DataBind()

           Transactions.CommittableTransaction.Current.Rollback()

       End Using

   End Sub

djibril_chimere_DIAW : On October 24, 2008 6:15 AM said:

Thanks !Jërëjëf!

shinji14 : On November 12, 2008 1:45 PM said:

Same as ASeventhSign and Piets, this code is supposse to delete also the referencs in orderdetails table?, because is throwing an exception about a foreign key.

shinji14 : On November 13, 2008 2:56 AM said:

well i dont sure if this video was created with a ctp version and this version supported cascade delete, anyway, to solve this activate the cascade option in sql server.

(in "foreign key relationship" window under "insert and update specification" change delete rule to "cascade")

che sos muy comillero xD

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities