A main goal for OO developers has been finding an easy solution to join the database world to the OO one. The former is composed by tables, columns, and a tabular way to store the data. The latter is formed by classes, relationships between them, and data stored within objects. The way to retrieve a record from the database is different from what OO developers are accustomed to with object manipulation. First of all, OO developers must know another language—SQL—to retrieve records from the database. Then they need to use the appropriate Application Programming Interface (API) to execute the queries from the code. Finally, developers must manipulate the retrieved data, looping through the collection of records.
Using the ADO.NET framework, one of the most powerful and complete APIs to manage the database from the code, these steps can be transformed into the following code snippet:string connString = "Data Source=.;Initial Catalog=AdventureWorks;" +
Note that for brevity, this sample code is not optimized, and it doesn’t contain exception handling. It’s intended to highlight some important aspects related to OO development:
One of the earlier OO approaches to the database world taken by Microsoft is the strongly typed dataset. With the use of the Visual Studio Dataset Designer, developers can drag tables from the Server Explorer window and drop them onto the designer surface. This operation generates a new class derived from the DataSet class, typed on source tables. Practically, this means that the class contains properties related to the table’s columns, with the same name and datatype. Moreover, the class contains a DataTable-derived class for each table dropped on the designer surface and the code to select and eventually update the database. In this way, calling just one method, Update from the DataAdapter class, the database is updated. The previous code snippet can be rewritten with the use of these classes, as follows:Products p = new Products();
Here, the Products class is inherited from a DataSet class and is typed upon the Products class from the AdventureWorks database. The ProductsTableAdapters contains the Fill method that accepts a ProductsDataTable parameter; it is useful to fill the Products dataset with records from the Products table. The Fill method runs the query specified during the class code generation with the Visual Studio Dataset Designer.
As you can see, the code is more readable and maintainable, providing properties that have the same name as related properties. It is an OO approach to the database records!
But this is just one little step toward what OO developers would have from their classes. The preceding example shows an automatic way to manage the database but contains a trick: the Visual Studio Dataset Designer generates SQL statements for you, but they are still in the class code! A purist doesn’t want to see mixed code in the class.
A pure O/RM tool allows developers to manage data without worrying about how to retrieve the data. Developers do not need to write any SQL code in their classes; they just manage classes and objects. The following pseudo-code snippet illustrates what a pure O/RM should provide:Products p = new Products();
Console.WriteLine(p.ProductID + ", " + p.Name);
The Retrieve imaginary method “knows” we are looking for the Product record that has the ProductID property equal to 1 and creates the SQL command for us, filling the Products class fields with the related values. It’s really gorgeous, isn’t it?
If you believe that the LINQ to SQL framework provides something similar to this pure O/RM code to manage a database, we have to inform you that this is only partially true. In fact, the LINQ to SQL framework provides basic O/RM functionality. As declared by Luca Bolognese (one of the creators of the LINQ to SQL framework) during a conference, LINQ to SQL has been provided with some basic O/RM features in the first release, and it will be expanded in future releases, thanks to feedback from the developers. In this chapter, you will see these features in action, and you will be able to use them in your projects. At the end of the chapter, you will have an idea of what the LINQ to SQL framework provides and what it doesn’t yet offer.
SQL Server 2008 Related Interview Questions
|SQL Server 2000 Interview Questions||MSBI Interview Questions|
|SQL Server 2008 Interview Questions||SQL Server 2005 Interview Questions|
|SSIS(SQL Server Integration Services) Interview Questions||SSRS(SQL Server Reporting Services) Interview Questions|
|Microsoft Entity Framework Interview Questions||LINQ Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||Sql Server Dba Interview Questions|
SQL Server 2008 Related Practice Tests
|SQL Server 2000 Practice Tests||MSBI Practice Tests|
|SQL Server 2008 Practice Tests||SQL Server 2005 Practice Tests|
|SSIS(SQL Server Integration Services) Practice Tests||SSRS(SQL Server Reporting Services) Practice Tests|
|Microsoft Entity Framework Practice Tests||LINQ Practice Tests|
Sql Server 2008 Tutorial
Sql Server 2008 Overview
Sql Server Installation And Configuration
Sql Server Encryption
Automation And Monitoring
Integrated Full-text Search
New Datatypes In Sql Server 2008
T-sql Enhancements For Developers
T-sql Enhancements For Dbas
Sql Server And Xml
Sql Server Xml And Xquery Support
Linq To Sql
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.