Wednesday, March 07, 2007

 

May 2006 to March 2007 comparison list

During the conversion I noted all the differences I found. Here follows the list:

===========================
CHAPTER 1 - Linq to Object
===========================
- System.Query namespace has been substituted with System.Linq
- System.Expressions namespace has been substituted with System.Linq.Expressions
- During the object's creation the compiler doesn't infer the data type anymore.

For example:

List roles = new List {
{ ID = 1, RoleDescription = "Manager" },
{ ID = 2, RoleDescription = "Developer" }
};

The snippet code above produces a compilation error.
You have to change to:

List roles = new List {
new Role { ID = 1, RoleDescription = "Manager" },
new Role { ID = 2, RoleDescription = "Developer" }
};

- Sequence static class has been substituted with Enumerable
- The EqualAll method has been substituted with SequenceEqual method
========================================
CHAPTER 2 - Linq to Sql/Linq to DataSet
========================================
- In order to use Linq To Sql you must add a reference to the new System.Data.Linq.dll assembly located into the C:\WINDOWS\Microsoft.NET\Framework\v3.5.20209 path
- InsertMethod, UpdateMethod and DeleteMethod attributes have been removed
- StoredProcedureResult and StoredProcedureMultipleResult classes have been removed. When your stored procedure returns a composed type the designer converts it into a new class
- ExecuteStoredProcedure<> method has been substituted with ExecuteMethodCall<>
- The T-SQL User defined functions are called using the new ExecuteMethodCall method instead of the old Expression.Call (that is still present in the framework)
- The new Linq to Sql designer generates a read-only property when it encounters a primary key column. If you wrote some code to remove a record from that table you can't call the Remove method specifying the ID anymore
- When an optimistic concurrency error occurres you receive a new exception: "System.Data.Linq.ChangeConflictException: Row not found or changed."
- The LocalTransaction property has been renamed into Transaction
- The AcceptChanges and RejectChanges methods have been removed
- The GetResults() method used in conjuction with StoredProcedureMultipleResult class to get part of the global query result has been removed (accordingly to the StoredProcedureMultipleResult deletion)
- The Including() method used to prefetch data and avoinding the continuos polling to the database to retrieve related data has been substituted with the LoadWith<> generic method provided by the new DataShape class. The new class provides a new method called AssociateWith<> useful to define a subquery against the prefetched records
- The methods to load a DataSet with a Linq to Sql query have been removed. You have to use your own methods such as suggested in this post
- The CopyToDataTable method has been added to load a DataTable from a Linq to DataSet query. It provides two versions: the former returns a new DataTable and doesn't accept parameters while the latter fills an existing DataTable provided as parameter plus a second parameter indicating the LoadOption options (i.e. overwrite records)
- The ToQueryable() method has been substituted with AsEnumerable()
- The ToBindingList() method has been removed. You can provide the Linq query to the DataSource property directly
========================
CHAPTER 3 - Linq to Xml
========================
- In order to use Linq To Xml you must add a reference to the new System.Xml.Linq.dll assembly located into the C:\WINDOWS\Microsoft.NET\Framework\v3.5.20209 path
- ElementsBeforeThis and ElementsAfterThis methods have been renamed into ElementsBeforeSelf and ElementsAfterSelf, respectively
- SetElement has been renamed into SetElementValue
- SetAttribute has been renamed into SetAttributeValue
- ReplaceContent has been renamed into ReplaceNodes (you can obtain the same result using ReplaceAll)
- RemoveContent has been renamed into RemoveNodes (you can obtain the same result using RemoveAll)

 

The new code for the Linq for Visual C# 2005 book

I have converted the Linq for Visual C# 2005 samples to work with the Orcas March 2007 CTP release.
You can download here.

This page is powered by Blogger. Isn't yours?