Create LINQ datacontext from Visual Studio From Visual Studio 2008 or later
-New project (optional)
-change target platform to .NET 3.5
-add\new "LINQ to SQL file"
-View\Server explorer
-Add connection
-drag a table onto the designer surface

More info and samples on: www.devarchweb.net

Create LINQ datacontext from command line From Visual Studio command line:
sqlmetal /server:(local) /database:basics /code:basics.cs

More info and samples on: www.devarchweb.net

Query data (person table)

var people = from p in db.persons
       where p.department_id > 0 && p.height>1
       orderby p.lastName
       select new
       {
         p.firstName,
         p.lastName,
       };


More info and samples on: www.devarchweb.net

Update data (person)

var person = (from p in db.persons select p).FirstOrDefault(); // select the record that you want to update
person.lastName = "Cernin"; // make the update in memory
db.SubmitChanges(); // propagate changes back to database


More info and samples on: www.devarchweb.net

Insert data (person)

person newP = new person();
newP.firstName = "John";
newP.height = 189;

db.persons.InsertOnSubmit(newP);
db.SubmitChanges();


More info and samples on: www.devarchweb.net

Delete data (person)

var personsToDelete = db.persons.Where(inst => inst.lastName == "Third"); // select who should be deleted
db.persons.DeleteOnSubmit(personsToDelete.First()); // execute the delete in memory
db.SubmitChanges(); // propagate changes back to database





More info and samples on: www.devarchweb.net