Linq

Linq also know as language integrated query, it means it is part of programming language syntax, C# and VB. Query means it facilitate quering the data.


Insert
The following code inserts a record in table.

DataClasses1DataContext db = new DataClasses1DataContext();

Table tbl = new Table();

tbl.Name = "John";
db.Tables.InsertOnSubmit(tbl);
db.SubmitChanges();

Select
The following code selects all records from a table.
List<string> names = new List<string>();
DataClasses1DataContext db = new DataClasses1DataContext();
var selectRecord = (from i in db.TableName select i).ToList();
if(selectRecord != null)
{
   names.Add(selectRecord.Name);
}

Count
The following code counts all records in table.
DataClasses1DataContext db = new DataClasses1DataContext();
var getCount = (from i in db.tbl_sample1s select i).Count();
Label.Text = getCount.ToString()+" record(s)";

Delete
The following code deletes a record in table based on ID.
DataClasses1DataContext db = new DataClasses1DataContext();
int ID = anyNumber;
var deleteRecord = db.TableName.FirstOrDefault(record => record.ID = = ID);
if (deleteRecord != null)
{
    db.TableName.DeleteOnSubmit(deleteRecord);
    db.SubmitChanges();
}

Update
The following code updates a record in table based on ID.
DataClasses1DataContext db = new DataClasses1DataContext();
int ID = anyNumber;
var editRecord = (from i in db.TableName where i.ID = = ID select i).FirstOrDefault();
if (editRecord != null)
{
   editRecord.Category = newValue;
   db.SubmitChanges();
}

Skip
The following code will skip first three records.
DataClasses1DataContext db = new DataClasses1DataContext();
var record = (from i in db.TableName select i).Skip(3);
List<string> names = new List<string>();
if(record != null)
{
   names.Add(record.Name);
}

For further question please mail: brainstormiert@gmail.com