Learning Video on LINQ to SQL Class

Source Code


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication9

{

class Program

{

static void Main(string[] args)

{

StudentDemoDataContext context = new StudentDemoDataContext();

#region Reterive

//Reteriving all the Records

foreach (var r in context.Students)

{

Console.WriteLine(r.Name + r.Subject);

}

#endregion

#region Insert

Student std = new Student

{

RollNumber = "8",

Name = "Mahesh",

Subject = "C#"

};

context.Students.InsertOnSubmit(std);

context.SubmitChanges();

#endregion

#region Update

Student std = (from r in context.Students

where r.RollNumber == "1"

select r).First();

std.Name = "Scott";

std.Subject = "ASP.Net MVC";

context.SubmitChanges();

#endregion

#region Delete

StudentDemoDataContext context1 = new StudentDemoDataContext();

Student std = new Student

{

RollNumber = "8",

Name = "Mahesh",

Subject = "C#"

};

context.Students.Attach(std);

context.Students.DeleteOnSubmit(std);

context.SubmitChanges();

#endregion

Console.Read();

}

}

}

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Create a website or blog at WordPress.com