Summary

As covered in this chapter, not only can you query normal DataSets with LINQ to DataSet, you can query typed DataSets. Typed DataSets make your code easier to maintain and more readable, and LINQ to DataSet makes querying those typed DataSets a breeze. I also demonstrated a more real-world LINQ to DataSet query that queried the Northwind database.

The LINQ to DataSet API adds yet another domain to those available for LINQ queries. With all the existing code already utilizing DataSets, LINQ to DataSet promises to be easy to retrofit into your legacy .NET code, thereby making it easier than ever to query data from a DataSet.

One benefit that the LINQ to DataSet API has over the LINQ to SQL API is the fact that no database class code needs to be generated and compiled ahead of time to perform LINQ to DataSet queries. This makes LINQ to DataSet more dynamic and suitable for database-type utilities where the databases will be unknown until runtime.

By providing the AsEnumerable operator to create sequences from DataTable objects, using the LINQ to Objects Standard Query Operators becomes possible, adding even more power to the arsenal of query capabilities.

For the LINQ to DataSet API, operators have been added for the key classes of the DataSet: DataTable, DataRow, and DataColumn. One must not forget the issue that makes the new set-type operator prototypes for the Distinct, Union, Intersect, Except, and SequenceEqual operators necessary: the problem that DataRows have being compared for equality. So when working with DataSets, DataTables, and DataRows, always opt for the LINQ to DataSet set-type operator prototypes for the Distinct, Union, Intersect, Except, and SequenceEqual operators where the equality comparer object is specified instead of the prototype versions without an equality comparer object being specified.

Lastly, when obtaining a column's value, use the Field<T> and SetField<T> operators to eliminate issues with comparisons for equality and null values.

One thing became apparent while working with the LINQ to DataSet API. I had totally underestimated the power and utility of DataSets. They offer so much in the way of a cached, relational data store. And while they already offer somewhat limited search facilities, with the LINQ to DataSet API, those limitations have been removed. You now have LINQ to query your DataSets with, and that makes coding just that much easier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset