1) Create a new project
File-> New Project -> Console Application.
2) Create a new Connection
1) Go to Server Explorer
2) Select "Data Connections" then right click and select "Add Connection"
3) This should add a new Connection to the Server Explorer. You should see your tables, Functions, Stored Procedures ... under this Connection object.
4) Now select your project Right click and select "Add New Item" and select "LinqToSql".
5) This should add .dbml file to your project.
6) This will create DataContext class in your project.
7) Now from the connection object selected in previous statement, add tables to your dbml.
8) which will consists of object model classes.
Create a object of that DataContext class and start using it.
DataClasses1DataContext dc = new DataClasses1DataContext();
////reading data from database
var empList = from c in dc.employees
select c;
foreach (var emp in empList)
{
Console.WriteLine("Emp Id: {0} " + "Emp Name:{1}", emp.emp_id, emp.emp_name);
}
//To insert data through LinqToSql
employee emp1 = new employee();
emp1.emp_id = "emp6";
emp1.emp_name = "emp6 Name";
dc.employees.InsertOnSubmit(emp1);
dc.SubmitChanges();
File-> New Project -> Console Application.
2) Create a new Connection
1) Go to Server Explorer
2) Select "Data Connections" then right click and select "Add Connection"
3) This should add a new Connection to the Server Explorer. You should see your tables, Functions, Stored Procedures ... under this Connection object.
4) Now select your project Right click and select "Add New Item" and select "LinqToSql".
5) This should add .dbml file to your project.
6) This will create DataContext class in your project.
7) Now from the connection object selected in previous statement, add tables to your dbml.
8) which will consists of object model classes.
Create a object of that DataContext class and start using it.
DataClasses1DataContext dc = new DataClasses1DataContext();
////reading data from database
var empList = from c in dc.employees
select c;
foreach (var emp in empList)
{
Console.WriteLine("Emp Id: {0} " + "Emp Name:{1}", emp.emp_id, emp.emp_name);
}
//To insert data through LinqToSql
employee emp1 = new employee();
emp1.emp_id = "emp6";
emp1.emp_name = "emp6 Name";
dc.employees.InsertOnSubmit(emp1);
dc.SubmitChanges();
No comments:
Post a Comment