LINQ – Language integrated query
It’s allows the programmer to express query behavior in their programming language of choice. It provide type safety and compile time valuation of expression.
LINQ supports three data source objects, XML and databases.
LINQ to SQL allows to represent the database objects in .Net classes, you can query the database as well as update/delete/insert the data.
It supports views, stored procedure and transactions, allows the integration validation logic into data model.
DataContext Class
For each LINQ to SQL class, there will be custom datacontext class will be generated. Properties will be added for each table and stored procedure we added into LINQ to SQL design surface.Datacontext is main conduit from which we query our entities from database.
//Connnection to database.
AdventureWorksDataContext db = new AdventureWorksDataContext();
//Query the datamodel through query.
var query = from p in db.Products
select p;
//Result of query
this.grid.datasource = query;
//Update/insert/delete change into database.
db.SubmitChanges();
Summary
LINQ to SQL provides a nice, clean way to model the data layer of your application.Once you've defined your data model you can easily and efficiently perform queries, inserts, updates and deletes against it.
No comments:
Post a Comment