I think most of you know that since moving back to the states, I’ve primarily been developing with ASP.NET 2.0 and only use PHP outside of work. I wish we could use .NET 3.5, but I work on Department of State projects and 3.5 hasn’t been approved for use yet so I’m stuck with 2.0 for now. In a couple of weeks though, I will be switching jobs and working on projects for the USDA (Dept. of Agriculture).
My team will be redeveloping an existing application that uses a combination of Coldfusion and Cobol and we will get to use .NET. We had a conference call on Thursday with the new team (they are in Kansas). They use Visual Studio 2008 TFS, but thought they were going to go with 2.0 instead of 3.5. I asked if there was anyway we could go with 3.5 instead since we will be starting from the ground-up and they said the decision was almost made to go with 2.0, but we could put a list of reasons to choose 3.5 together and they would present it to the decision making folks.
So, that night I rolled up my sleeves and got to researching and writing. I read a lot of .net blogs so I knew the basics of what made 3.5 so great, but really wanted to provide some good examples. I think I compiled a halfway decent list and a few blogs in particular really helped explain the benefits such as Mark’s C# Shortcuts and Scott Guthrie’s Summary on Visual Studio 2008 and .NET 3.5.
I do not know if this argument was persuasive yet and may not know for another couple of weeks. I am posting this so in case someone else needs to convince their boss or client to choose 3.5, this might prove helpful. If you know of any other reasons as well, I would love to hear them. This is written from the viewpoint of someone who doesn’t have any experience with the 3.5 framework. Thanks to my friends (Ben, Nancy, Doug, and Jenn) for helping review this and adding their own thoughts to it!
Introduction
Microsoft .Net 3.5 was released almost a year ago (November 19, 2007) and has been out long enough for any kinks in the system to have been worked out. While the 3.5 Framework was built on top of 2.0, it has some great features which make it easier to develop applications as well as facilitating a better end-user experience. Some of the enhancements to the 3.5 framework are:
- Support for LINQ
- New Data Controls
- Cleaner Coding via Language Improvements
- Built-in ASP.NET AJAX support
LINQ
One of the enhancements we are most excited about is LINQ, which stands for Language Integrated Query. LINQ allows developers to build a query dynamically not only on databases, but also on objects and XML. We prefer to use stored procedures in our development and LINQ can also be used with the procedures.
LINQ to SQL
LINQ to SQL is an Object Relational Mapping implementation which allows developers to easily model a relational database and execute queries (to include inserts and updates). LINQ makes it very easy to query the database. Below is an example which shows how easily you can pull data from the database:
Easy way to Query Data using LINQ |
//Create data context for LINQ |
DataContext db = new DataContext(connectionString); |
Table customers = db.GetTable(); |
//Query database |
var custs = from c in customers select c; |
LINQ to Dataset
In ASP.NET 2.0, neither the DataTable nor the DataSet implement IEnumerable or IQueryable, but LINQ to DataSet treats DataTables as enumerations of DataRow Objects and lets developers query DataSets and DataTables.
New Data Controls
In ASP.NET 2.0, the GridView, DataView, and FormView all have paging built in out of the box, but it has its limitations such as having the paging interface appear detached from the actual control itself. The DataPager control offered in 3.5, addresses these limitations by allowing the paging functionality to be independent of the control and appear anywhere on the web page.
The ListView is a new control which combines the best functionality of the DataGrid (editing features) and the Repeater (templating, control over markup) controls.
Cleaner Coding and Language Improvements
Improved HTML Markup
ASP.NET has never had a good reputation for generating clean HTML. While ASP.NET 2.0 provided more control over the HTML markup generated than 1.1, some of the controls still produced the same garbage, but with the new data controls in ASP.NET 3.5, the developer has more control over the HTML that is rendered which is a great thing for the end-users.
Automatic Properties
This improvement is best explained visually. Below is a nice “before and after†example but basically this would be an immense time saver especially when dealing in migration issues when many “supporting†methods and properties need to be re- created to facilitate platform migration.
In 2.0, the developer needed to declare a private property and then set Getters and Setters to access that property as in the example below:
Properties in the .NET 2.0 Framework |
public string |
{ |
get { return _address; } |
set { _address = value; } |
} |
In 3.5, the C# compiler creates the Getters and Setters and the private field automatically. This is just an obvious time saver and makes code much cleaner for review and maintenance.
Automatic Properties in the .NET 3.5 Framework |
public string Address {get; set;} |
Object Initializers
In 2.0, when developers instantiate an object with a default constructor, they need to call the constructor, and assign values individually to the object’s properties:
Instantiating a class in the .NET 2.0 Framework |
Employee emp = new Employee(); |
emp.FirstName = “Saraâ€; |
emp.LastName = “Smithâ€; |
emp.EmployeeID = “SI-12345â€; |
In 3.5, the C# compiler automatically generates the appropriate property setter code(s):
Object Initializers in the .NET 3.5 Framework |
Employee emp = new Employee { FirstName=â€Saraâ€, LastName=â€Smithâ€}; |
Collection Initializers
When developers need to add a series of objects to a Collection in 2.0, it is necessary to add each object one by one to the collection. In 3.5 however, the C# compiler supports collection initializers which allows us to add as many objects as we want during the initialization process rather than adding them individually:
Collection Initializers in the .NET 3.5 Framework |
List employees = new List { |
new Employee { FirstName=â€Saraâ€, LastName=â€Smithâ€}, |
new Employee { FirstName=â€Benâ€, LastName=â€Jonesâ€} |
}; |
Type Inference
This is something developers are used to seeing in JavaScript, but in 3.5, the C# compiler can infer what type of variable is being created simply by looking at the value being assigned. This type of intuitive functionality becomes a great “on the fly†feature
Type Inference in the .NET 3.5 Framework |
var message = “Choose .NET 3.5!â€; |
Built-In ASP.Net AJAX
AJAX provides end-users with a rich, interactive, user-experience. .NET 2.0 required a separate download to work with ASP.NET AJAX, but 3.5 has this functionality built-in along with extra improvements. Visual Studio 2008 is optimized to work with the 3.5 framework.
Conclusion
As developers, the .Net 3.5 Framework provides us with a more concise and efficient way to work with objects and collections as well as working with data. With new controls like the ListView and DataPager, we have complete control over the markup sent to the browser, while still providing data paging and data manipulation capabilities. Using .Net 3.5 instead of 2.0 will allow us to build better applications, and build them quickly thus making the foundation for future releases and maintenance much more accommodating. .NET 3.5 has been thoroughly tested and is recommended for any new projects.
For projects still in their infancy and their future is not set in stone, taking the pro-active leap to incorporate a technology whose future is virtually guaranteed is the type of forward thinking decision which can only benefit all parties concerned. Since much of the product support is provided by the development community, as developers continue to move to 3.5, support for 2.0 will dwindle. We recommend using it over 2.0 because in the long run an application written in 3.5 will require less rewrites and make for a better final product for the user.