Inserting records using LinqToSql

I wasn’t able to find any good examples on Google (they were all for old CTPs).
So to all that this may help, this is how you can insert a record into SQL using Linq (LinqToSQL).

NorthWindDataContext db = new NorthWindDataContext();
Product prod = new Product();
prod.ProductName = "The Dave Special";
prod.CategoryID = 1;
prod.UnitPrice = 24;
prod.UnitsInStock = 1;

//This is the line I kept missing


A shout out to Jordan Knight for helping me with this

By David Burela

One thought on “Inserting records using LinqToSql

  1. Hey, its so simple but i was having the hardest time doing exactly this… your a lifesaver… maybe thats a little to extreme. Your a timesaver… and a lifesaver.

    thanks again!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s