SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 347 | Next

Scott Klein

"Professional LINQ"

The next section explains how.
DataContext
Before you can execute a LINQ to SQL query, a connection to the data source must be made. In LINQ
to SQL, database connections are made through the DataContext class. Think of the DataContext class
on the same level as you would the SqlConnection class of ADO.NET. DataContext is the medium in
which connections to a database are made, through which objects are retrieved from and submitted to
the database.
Like the SqlConnection class, the DataContext instance accepts a connection string. Once the connection
is made, data is read from, and changes are transmitted back to, the database through the DataContext.
However, there is one thing the DataContext does that the SqlConnection does not. Since LINQ to SQL
deals with objects, the DataContext also does the work of converting the objects into SQL queries and
then reassembling the results back into queryable objects.
The DataContext has several overloads, one of which is just a simple connection string specifying the
connection information, as shown in this code:
DataContext db = new DataContext(
"Initial Catalog=AdventureWorks;Integrated i
Security=sspi");
You can also pass an IDbConnection, which represents an open connection to a data source.


Pages:
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6