Wednesday, October 22, 2008

Dotnet 3.5 new features.

1. INTRODUCTION
This document presents information about new and enhanced features in the .NET Framework version 3.5. .NET Framework 3.5 builds incrementally on the new features that were added in .NET Framework 3.0. In addition, .NET Framework 3.5 contains some new features which have been added as new assemblies to avoid breaking changes. The document aims at providing information about enhanced features incorporated in .Net Framework 3.5 which includes LINQ, Asp.Net, CLR, Cryptography, and Networking etc excluding language change features.
Points 2 to 13 explain every enhancement in detail.

2. .NET Compact Framework
The .NET Compact Framework version 3.5 expands support for distributed mobile applications by including the Windows Communication Foundation (WCF) technology. It also adds new language features such as LINQ; new APIs based on community feedback, and improves debugging with updated diagnostic tools and features.
The new features are listed below:
A. Windows Communication Foundation
The .NET Compact Framework 3.5 supports Windows Communication Foundation (WCF), which is Microsoft’s unified programming model for building service-oriented applications. Clients that are running the .NET Compact Framework can connect to existing WCF Web services on the desktop. In addition, support for a new WCF transport, the Microsoft Exchange Server mail transport, has been added for both .NET Compact Framework applications and desktop applications.
B. LINQ
Language-Integrated Query (LINQ) adds general-purpose query facilities to the .NET Compact Framework that apply to various sources of information such as relational databases, XML data, and in-memory objects.
C. Windows Forms
The following table describes the improvements that have been made to Windows Forms controls in the .NET Compact Framework 3.5.


Type Changes
TabPage
Panel
Splitter
Picture Box Users can now add graphics to these controls.
Control ClearType fonts are now supported, and you can modify the BackColor property on read-only controls.

ComboBox The SelectionStart and SelectionLength properties are now supported.

D. SoundPlayer
The .NET Compact Framework 3.5 supports SoundPlayer, which enables you to play multiple sounds. A device can mix these sounds if the hardware supports this capability.
E. Compression
The .NET Compact Framework 3.5 adds support for the following classes in the System.IO.Compression namespace:
 CompressionMode
 DeflateStream
 GZipStream
In addition, the AutomaticDecompression property is supported.
F. Delegates
The .NET Compact Framework 3.5 supports the CreateDelegate method.
G. The .NET Compact Framework CLR Profiler
The .NET Compact Framework 3.5 supports the CLR Profiler, which was previously available only with the full .NET Framework. The CLR Profiler enables you to view the managed heap of a process and investigate the behavior of the garbage collector. The CLR Profiler and its associated documentation are included in the Power Toys for .NET Compact Framework.

Note:

The CLR Profiler requires the .NET Framework version 3.5 on the desktop.

H. Configuration Tool
The .NET Compact Framework 3.5 supports the Configuration Tool, which provides runtime version information and administrative functions, such as specifying which version of the .NET Compact Framework an application will run against. The Configuration Tool and its associated documentation are included in the Power Toys for .NET Compact Framework.
I. Debugging
Debugging enhancements to the .NET Compact Framework 3.5 include the following:
 Nested function evaluations are now supported.
 Unhandled exceptions now break where the exception occurred instead of breaking where you call the Run method.
J. Logging
The following improvements have been made to logging features:
 Interop logs now include information about marshaled objects that are contained in structures or in reference types.
 Finalizer logging now includes information about the order and timing of the finalizer.
 Log files are no longer locked while the application is running. Therefore, you can read the logs at run time.
 Stack traces now include the full method signature to distinguish method overloads.
K. Platform ID
The .NET Compact Framework 3.5 provides new information about the platform type, specifically whether a platform is a Pocket PC or a Smartphone.
L. Runtime Tools
The runtime tools library now provides support for running .NET Compact Framework SDK diagnostic tools, such as Remote Performance Monitor, with the emulator. The runtime tools and their associated documentation are included in the Power Toys for .NET Compact Framework.
M. Strong Names
Strong names that are greater than 1,024 bytes are now supported.
N. Global Assembly Cache
Modifications to the architecture of the global assembly provide improved error handling and integration with Windows Embedded CE version 6.0.
O. Documentation
The class library documentation for the .NET Compact Framework 3.5 includes improved platform support information for overloads
P. Samples
New samples are available that demonstrate features of the .NET Compact Framework 3.5 such as WCF, compression, LINQ, and XLINQ.

3. ASP.NET
The .NET Framework 3.5 includes enhancements in targeted areas of ASP.NET and Visual Web Developer. The most significant advance is improved support for the development of AJAX-enabled Web sites. ASP.NET supports server-centric AJAX development with a set of new server controls and APIs. You can enable an existing ASP.NET 2.0 page for AJAX by adding a ScriptManager control and an UpdatePanel control so that the page can update without requiring a full page refresh.
ASP.NET also supports client-centric AJAX development with a new client library called the Microsoft AJAX Library. The Microsoft AJAX Library supports client-centric, object-oriented development, which is browser-independent. By using the library classes in your ECMAScript (JavaScript) you can enable rich UI behaviors without roundtrips to the server. You can mix the degree of server-centric and client-centric development to meet the needs of your application. Furthermore, Visual Web Developer includes improved IntelliSense support for JavaScript and support for the Microsoft AJAX Library.
ASP.NET and Visual Web Developer now support the creation of both ASMX and WCF-based Web services and the seamless use of either implementation from Web pages using Microsoft AJAX Library. Furthermore, server-side application services including forms authentication, roles management, and profiles are now exposed as Web services that can be consumed in WCF-compatible applications, including client script and Window Forms clients. ASP.NET enables all Web-based applications to share these common application services.
Other improvements in ASP.NET include a new data control, ListView, for displaying data; a new data source control, LinqDataSource, that exposes Language Integrated Query (LINQ) to Web developers through the ASP.NET data source control architectures; a new tool, ASP.NET Merge Tool (Aspnet_merge.exe) for merging precompiled assemblies; and tight integration with IIS 7.0. ListView is a highly customizable control (using templates and styles) that also supports edit, insert, and delete operations, as well as sorting and paging functionality. The paging functionality for ListView is provided by a new control called DataPager. You can use the merge tool to combine assemblies to support a range of deployment and release management scenarios. The integration of ASP.NET and IIS 7.0 includes the ability to use ASP.NET services, such as authentication and caching, for any content type. It also includes the ability to develop server pipeline modules in ASP.NET managed code and supports unified configuration of modules and handlers.
Other improvements in Visual Web Developer include multitargeting support, inclusion of Web Application Projects, a new Design view, new Cascading Style Sheets (CSS) design tools, and support for LINQ for SQL databases. Multitargeting enables you to use Visual Web Developer to target development of Web applications to specific versions of the .NET Framework, including versions 2.0, 3.0, and 3.5.
4. Add-Ins and Extensibility
The System.AddIn.dll assembly in the .NET Framework 3.5 provides powerful and flexible support to developers of extensible applications. It introduces a new architecture and model that helps developers with the initial work to add extensibility to an application and by ensuring that their extensions continue working as the host application changes. The model provides the following features:
 Discovery
You can easily find and manage sets of add-ins in multiple locations on a computer with the AddInStore class. You can use this class to search for and obtain information about add-ins by their base types without having to load them.
 Activation
After an application chooses an add-in, the AddInToken class makes it easy to activate. Simply choose the isolation and sandboxing level and the system takes care of the rest.
 Isolation
There is built-in support for application domains and process isolation of add-ins. The isolation level for each add-in is in the control of the host. The system handles loading application domains and processes and shutting them down after their add-ins have stopped running.
 Sandboxing
You can easily configure add-ins with either a default or customized trust level. Support includes Internet, Intranet, Full Trust, and “same-as-host” permission sets, as well as overloads that let the host specify a custom permission set.
 UI Composition
The add-in model supports direct composition of Windows Presentation Foundation (WPF) controls that span application domain boundaries. You can easily allow add-ins to contribute directly to the UI of the host while still retaining the benefits of isolation, ability to unload, sandboxing, and versioning.
 Versioning
The add-in architecture makes it possible for hosts to introduce new versions of their object model without breaking existing add-ins or impacting the developer experience for new ones.

5. Common Language Runtime
A. Collections
HashSet (T) provides high performance set operations to the .NET Framework. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.
B. Diagnostics
The EventSchemaTraceListener class provides tracing of end-to-end, schema-compliant events. You can use end-to-end tracing for a system that has heterogeneous components that cross thread, AppDomain, process, and computer boundaries. A standardized event schema has been defined to enable tracing across these boundaries. This schema is shared by various tracing technologies, including Windows Vista diagnostics tools such as Event Viewer. The schema also enables the addition of custom, schema-compliant elements.
The EventSchemaTraceListener class is tuned for logging performance with implicit support for lock-free tracing.
C. I/O and Pipes
Pipes provide interprocess communication between any processes running on the same computer, or on any other Windows computer within a network. The .NET Framework provides access to two types of pipes: anonymous pipes and named pipes
D. Garbage Collection
The GCSettings class has a new LatencyMode property that you can use to adjust the time that the garbage collector intrudes in your application. You set this property to one of the values of the new GCLatencyMode enumeration.
The GC class has a new Collect (Int32, GCCollectionMode) method overload that you can use to adjust the behavior for a forced garbage collection. For example, you can use this overload to specify that the garbage collector should determine whether the current time is optimal to reclaim objects. This overload takes a value from the new GCCollectionMode enumeration.
E. Reflection and Reflection Emit in Partial Trust
Assemblies that run with partial trust can now emit code and execute it. Emitted code that calls only public types and methods needs no permissions beyond the permissions demanded by the types and methods that are accessed. The new DynamicMethod (String, Type, Type []) constructor makes it easy to emit such code.
When emitted code needs to access private data, the new DynamicMethod (String, Type, Type [], Boolean) constructor allows restricted access. The host must grant ReflectionPermission with the new RestrictedMemberAccess flag to enable this feature, which gives emitted code the ability to access private data only for types and methods in assemblies with equal or lesser trust levels. For reflection, a host grant of RestrictedMemberAccess similarly allows restricted use of methods that access private properties, call private methods, and so on, but only for target assemblies with equal or lesser trust levels.
F. Threading
I. Better Reader/Writer Lock
The new ReaderWriterLockSlim class provides performance that is significantly better than ReaderWriterLock, and comparable with the lock statement (SyncLock in Visual Basic). Transitions between lock states have been simplified to make programming easier and to reduce the chances of deadlocks. The new class supports recursion to simplify migration from lock and from ReaderWriterLock.
II. ThreadPool Performance Enhancements
Throughput for the dispatch of work items and I/O tasks in the managed thread pool is significantly improved. Dispatch is now handled in managed code, without transitions to unmanaged code and with fewer locks. The use of ThreadPool is recommended over application-specific thread pool implementations.
III. Time Zone Improvements
Two new types, DateTimeOffset and TimeZoneInfo, improve support for time zones and make it easier to develop applications that work with dates and times in different time zones.
IV. TimeZoneInfo
The new TimeZoneInfo class largely supplants the existing TimeZone class. You can use TimeZoneInfo to retrieve any time zone defined in the registry, rather than just the local time zone and Coordinated Universal Time (UTC). You can also use this class to define custom time zones, to serialize and deserialize custom time zone data, and to convert times between time zones.
V. DateTimeOffset
The new DateTimeOffset structure extends the DateTime structure to make working with times across time zones easier. The DateTimeOffset structure stores date and time information as a UTC date and time together with an offset value that indicates how much the time differs from UTC.

6. Cryptography
A. ClickOnce Manifests
There are new cryptography classes for verifying and obtaining information about manifest signatures for ClickOnce applications. The ManifestSignatureInformation class obtains information about a manifest signature when you use its VerifySignature method overloads. You can use the ManifestKinds enumeration to specify which manifests to verify. The result of the verification is one of the SignatureVerificationResult enumeration values. The ManifestSignatureInformationCollection provides a read-only collection of ManifestSignatureInformation objects of the verified signatures. In addition, the following classes provide specific signature information:
 StrongNameSignatureInformatio:
Holds the strong name signature information for a manifest.
 AuthenticodeSignatureInformation
Represents the Authenticode signature information for a manifest.
 TimestampInformation
Contains information about the time stamp on an Authenticode signature.
 TrustStatus
Provides a simple way to check whether an Authenticode signature is trusted.
B. Suite B Support
The .NET Framework 3.5 supports the Suite B set of cryptographic algorithms published by the National Security Agency (NSA).
The following algorithms are included:
 Advanced Encryption Standard (AES) with key sizes of 128 and 256 bits for encryption.
 Secure Hash Algorithm (SHA-256 and SHA-384) for hashing.
 Elliptic Curve Digital Signature Algorithm (ECDSA) using curves of 256-bit and 384-bit prime moduli for signing. This algorithm is provided by the ECDsaCng class. It allows you to sign with a private key and verify with a public key.
 Elliptic Curve Diffie-Hellman (ECDH) using curves of 256 and 384-bit prime moduli for key exchange/secret agreement. This algorithm is provided by the ECDiffieHellmanCng class.
Managed code wrappers for the Federal Information Processing Standard (FIPS) certified implementations of the AES, SHA-256, and SHA-384 implementations are available in the new AesCryptoServiceProvider, SHA256CryptoServiceProvider, and SHA384CryptoServiceProvider classes.
The Cryptography Next Generation (CNG) classes provide a managed implementation of the native Crypto API (CAPI). Central to this group is the CngKey key container class, which abstracts the storage and use of CNG keys. This class allows you to store a key pair or a public key securely and refer to it using a simple string name. The ECDsaCng and ECDiffieHellmanCng classes use CngKey objects.
The CngKey class is used for a variety of additional operations, including opening, creating, deleting, and exporting keys. It also provides access to the underlying key handle to use when calling native APIs directly.
There is a variety of supporting CNG classes, such as CngProvider, which maintains a key storage provider, CngAlgorithm, which maintains a CNG algorithm, and CngProperty, which maintains commonly used key properties.

7. Networking
A. Peer-to-Peer Networking
Peer-to-peer networking is a serverless networking technology that allows several network devices to share resources and communicate directly with each other. The System.Net.PeerToPeer namespace provides a set of classes that support the Peer Name Resolution Protocol (PNRP) that allows the discovery of other peer nodes through PeerName objects registered within a peer-to-peer cloud. PNRP can resolve peer names to IPv6 or IPv4 IP addresses.
B. Collaboration Using Peer-to-Peer Networking
The System.Net.PeerToPeer.Collaboration namespace provides a set of classes that support collaboration using the Peer-to-Peer networking infrastructure. These classes simplify the process by which applications can:
 Track peer presence without a server.
 Send invitations to participants.
 Discover peers on the same subnet or LAN.
 Manage contacts.
 Interact with peers.
Microsoft’s Peer-to-Peer collaboration infrastructure provides a peer-to-peer network-based framework for collaborative serverless activities. Use of this framework enables decentralized networking applications that use the collective power of computers over a subnet or the Internet. These types of applications can be used for activities such as collaborative planning, communication, content distribution, or even multiplayer game matchmaking.
C. Socket Performance Enhancements
The Socket class has been enhanced for use by applications that use asynchronous network I/O to achieve the highest performance. A series of new classes have been added as part of a set of enhancements to the Socket namespace. These classes provide an alternative asynchronous pattern that can be used by specialized high-performance socket applications. These enhancements were specifically designed for network server applications that require the high-performance.
8. Windows Communication Foundation
A. WCF and WF Integration—Workflow Services
The .NET Framework 3.5 unifies the Windows Workflow Foundation (WF) and Windows Communication Foundation (WCF) frameworks so that you can use WF as a way to author WCF services or expose your existing WF workflow as a service. This enables you to create services that can be persisted, can easily transfer data in and out of a workflow, and can enforce application-level protocols.
B. Durable Services
The .NET Framework 3.5 also introduces support for WCF services that use the WF persistence model to persist the state information of the service. These durable services persist their state information on the application layer, so that if a session is torn down and re-created later, the state information for that service can be reloaded from the persistence store.
C. WCF Web Programming Model
The WCF Web Programming Model enables developers to build Web-style services with WCF. The Web Programming Model includes rich URI processing capability, support for all HTTP verbs including GET, and a simple programming model for working with a wide variety of message formats (including XML, JSON, and opaque binary streams).
D. WCF Syndication
WCF now includes a strongly typed object model for processing syndication feeds, including both the Atom 1.0 and RSS 2.0 formats
E. WCF and Partial Trust
In .NET Framework 3.5, applications running with reduced permissions can use a limited subset of WCF features. Server applications running with ASP.NET Medium Trust permissions can use the WCF Service Model to create basic HTTP services. Client applications running with Internet Zone permissions (such as XAML Browser Applications or unsigned applications deployed with ClickOnce) can use the WCF proxies to consume HTTP services. In addition, the WCF Web Programming Model features (including AJAX and Syndication) are available for use by partially trusted applications.
F. WCF and ASP.NET AJAX Integration
The integration of WCF with the Asynchronous JavaScript and XML (AJAX) capabilities in ASP.NET provides an end-to-end programming model for building Web applications that can use WCF services. In AJAX-style Web applications, the client (for example, the browser in a Web application) exchanges small amounts of data with the server by using asynchronous requests. Integration with AJAX features in ASP.NET provides an easy way to build WCF Web services that are accessible by using client JavaScript in the browser.
G. Web Services Interoperability
In the .NET Framework 3.5, Microsoft maintains its commitment to interoperability and public standards and introduces support for the new secure, reliable, and transacted Web services standards:
 Web Services Reliable Messaging v1.1
 Web Services Reliable Messaging Policy Assertion v1.1
 WS-SecureConversation v1.3
 WS-Trust v1.3
 WS-SecurityPolicy v1.2
 Web Services Atomic Transaction (WS-AtomicTransaction) Version 1.1
 Web Services Coordination (WS-Coordination) Version 1.1
 Web Services Policy 1.5 - Framework
 Web Services Policy 1.5 - Attachment
9. Windows Presentation Foundation
In the .NET Framework 3.5, Windows Presentation Foundation contains changes and improvements in numerous areas, including versioning, the application model, data binding, controls, documents, annotations, and 3-D UI elements.

10. Windows Workflow Foundation
A. WCF and WF Integration—Workflow Services
The .NET Framework 3.5 unifies the Windows Workflow Foundation (WF) and Windows Communication Foundation (WF) frameworks so that you can use WF as a way to author WCF services or expose your existing WF workflow as a service. This enables you to create services that can be persisted, can easily transfer data in and out of a workflow, and can enforce application-level protocols.
B. Rules
The WF rules engine now supports extension methods, operator overloading, and the use of the new operator in your rules.
11. Windows Forms
A. ClickOnce Improvements
Several improvements have been made to ClickOnce. Improvements include deployment from multiple locations and third-party branding.
The Mage.exe tool, which is sometimes used together with ClickOnce, has been updated for the .NET Framework 3.5
B. Authentication, Roles, and Settings Services
Client application services are new in the .NET Framework 3.5 and enable Windows-based applications (including Windows Forms and Windows Presentation Foundation applications) to easily access the ASP.NET login, roles, and profile services. These services enable you to authenticate users and retrieve user roles and application settings from a shared server.
You can enable client application service


New Features in ASP.NET 3.5









TABLE OF CONTENTS
1. Introduction 3
2. New Features in ASP.NET 3.5 3
3. ASP.NET AJAX 3
4. New Controls 3
5. The ListView Control 4
6. Basic Data Display with the ListView 5
7. DataPager (Adding Paging) 6
8. LINQ 7
9. ASP.NET Merge Tool 10
10. New Assemblies 10
11. Some Other Important Points 11

Introduction
Microsoft released ASP.NET 3.5 on November 19, 2007. Along with it, was released Visual Studio 2008. This evolution from ASP.NET 2.0 to ASP.NET 3.5 is quiet gradual. ASP.NET 3.5 uses the same engine as that of ASP.NET 2.0, with some extra features added on top of it. In this white paper, we will explore the new features added to ASP.NET 3.5.
New Features in ASP.NET 3.5

ASP.NET AJAX
In ASP.NET 2.0, ASP.NET AJAX was used as an extension to it. You had to download the extensions and install it. However in ASP.NET 3.5, ASP.NET AJAX is integrated into the .NET Framework, thereby making the process of building cool user interfaces easier and intuitive. The integration between web parts and the update panel is much smoother. Another noticeable feature is that you can now add ASP.NET AJAX Control Extenders to the toolbox in VS2008.

Even though this is an IDE specific feature, however I feel it deserves a mention over here for developers, who had to add extenders using source view earlier. It is also worth noting that Windows Communication Foundation (WCF) now supports JSON along with other standard protocols like SOAP, RSS and POX.

New Controls
The ListView and DataPager are new controls added along with a new datasource control called the LinqDataSource.



The ListView Control
The ListView control is quiet flexible and contains features of the GridView, DataGrid, Repeater and similar list controls available in ASP.NET 2.0. It provides the ability to insert, delete, page (using Data Pager), sort and edit data. However one feature of the ListView control that stands apart is that it gives you a great amount of flexibility over the markup generated. So you have a complete control on how the data is to be displayed. You can now render your data without using the tag. You also get a rich set of templates with the ListView control.
Using the ListView for basic data display is very similar to using a Repeater. You have the ListView control and a set of templates that you can apply which include:
• LayoutTemplate
• ItemTemplate
• AlternatingItemTemplate
• SelectedItemTemplate
• EmptyItemTemplate
• EmptyDataTemplate
• ItemSeparatorTemplate
• GroupTemplate
• GroupSeparatorTemplate
• EditItemTemplate
• InsertItemTemplate
There are a few new ones here like GroupTemplate and InsertItemTemplate. InsertItemTemplate certainly is a nice addition so you can handle both editing and adding in the same space (previously with a DataGrid you had to insertion externally or insert data manually into a DataTable to display the empty row).

Playing around with this control feels nice in that you have all the control in the world to make it do what you want for rendering at the cost of a bit more markup code you have to create on your own. But personally I find that I struggle with DataGrid/GridView type issues anyway and think it's actually easier to put the layout together yourself and get really what you want rather than wade through abstracted properties 5 controls deep in GridView layout. It's much easier to create custom layouts for both display and editing.

Basic Data Display with the ListView
So to start off think of the ListView as a Repeater on steroids - everything is template driven including a 'master' layout template which is the layout template. For example a simple view might look like this:
DataSourceID="Data"
ItemContainerID="layoutTemplate"
DataKeyNames="Pk" >






<%# Eval("Name") %>

<%# Eval("EmpID") %>







DataPager (Adding Paging)
DataPager provides paging support to the ListView control. The best advantage is that you need not have to keep it ‘tied’ with the control on which the paging is being done. You can keep it anywhere on the page. DataPager gives you a consistent way of paging with the controls that support it. Currently only ListView supports it as it implements the IPageableItemContainer.

However support is likely to be added to other List controls as well. The pager also is an Inline element so it doesn't force any particular positioning on you - you can simply wrap it in a div to format it as you like.
To place a page I can use markup like this to put the pager anywhere on the page:

PagedControlID="lvItems" PageSize="5" >

PreviousPageText="..." />
LastPageText="Last"
NextPageText="Next" PreviousPageText="Previous" />




As you can see there are template fields inside of the DataPager so you can control the layout of the pager which is handy. The key to this control is the PagedControlID which points at a ListView. You specify a page size and that's all there's to it. You can also stick the Pager control into the Layout Template if you choose so the Pager can be a direct part of the generated output.

LINQ
LINQ (Language Integrated Query) adds native data querying capability to C# and VB.NET along with the compiler and Intelligence support. LINQ is a component of .NET 3.5. LINQ defines operators that allow you to code your query in a consistent manner over databases, objects and XML. The ASP.NET LinqDataSource control allows you to use LINQ to filter, order and group data before binding to the List controls.

In this white paper, I am going to explain you how to work with LINQ to SQL Classes and LinqDataSource control. For this, you will need .NET Framework 3.5, Visual Web Developer 2008, and SQL Server Express Database.

In order to work with LinqDataSource control, let’s create a database first.



Right click the App_Data folder and select Add New Item. Select SQL Server Database and click Add. Go to database explorer and explore the Database > Tables. Right click Tables and click Add New Table. Create following fields as displayed in the image below.




Now its time to create a LINQ to SQL classes. This can work as your Data Access Layer of the application. For this, right click the project folder in the solution explorer and select Add ASP.NET Folder and Select App_Code. Right click App_Code folder and select LINQ to SQL Classes and add it. You will see that you will have a DataClasses.dbml file into the App_Code folder.

Double click DataClasses.dbml to open it into Object Relational Designer (ORD) window. Now its time to drag the Address table into ORD from Database Explorer. Go to Database Explorer and drag the Address table to the ORD window. This will create two more file into App_Code related with DataClasses.dbml named DataClasses.dbml.layout and DataClasses.designer.cs or .vb depending upon what language you have selected and save DataClasses.dbml.




Till now we have created LINQ to SQL Classes and linked it with the database table. You can open DataClasses.designer.cs file and see what sorts of code have been generated automatically to deal with the Address database table.



Now we can link our LinqDataSource control with this LINQ to SQL Classes. To do that, create a new .aspx page, go to Design view and drag LinqDataSource control from data tab of the Toolbox.

Open the smart tag of LinqDataSource control and select Configure Data Source. In the Context Object list, select DataClassesDataContext from the dropdown and click next. Now select Addresses (Table
) from the table dropdown list and click Finish.

To allow manipulating the data of the database, again open the smart tag of the LinqDataSource control and select Enable Insert, Enable Delete and Enable Update checkboxes.




Now your LinqDataSource control is ready to be attached with any Data controls like GridView, ListView etc. Just drag a GridView from Data tab and specify the DataSource property to the LinqDataSource control. Run your .aspx page and you will see that your GridView is populating records from the database through LinqDataSource control efficiently and easily.



ASP.NET Merge Tool
ASP.NET 3.5 includes a new merge tool (aspnet_merge.exe). This tool lets you combine and manage assemblies created by aspnet_compiler.exe. This tool was available earlier as an add-on.
New Assemblies
The new assemblies that would be of use to ASP.NET 3.5 developers are as follows:

 System.Core.dll - Includes the implementation for LINQ to Objects
 System.Data.Linq.dll - Includes the implementation for LINQ to SQL
 System.Xml.Linq.dll - Includes the implementation for LINQ to XML
 System.Data.DataSetExtensions.dll - Includes the implementation for LINQ to DataSet.
 System.Web.Extensions.dll - Includes the implementation for ASP.NET AJAX (new enhancements added) and new web controls as explained earlier.



Some Other Important Points
 ASP.NET 3.5 provides better support to IIS7. IIS7 and ASP.NET 3.5 modules and handlers support unified configuration.
 You can have multiple versions of ASP.NET on the same machine.
 For those who are wondering what happened to ASP.NET 3.0, well there isn’t anything called ASP.NET 3.0.
 VS 2002 worked with ASP.NET 1.0, VS 2003 worked with ASP.NET 1.1, and VS 2005 worked with ASP.NET 2.0. However VS 2008 supports multi-targeting, that is it works with ASP.NET 2.0, and ASP.NET 3.5.


TABLE OF CONTENTS
1. Introduction 3
2. New Features in ASP.NET 3.5 3
3. ASP.NET AJAX 3
4. New Controls 3
5. The ListView Control 4
6. Basic Data Display with the ListView 5
7. DataPager (Adding Paging) 6
8. LINQ 7
9. ASP.NET Merge Tool 10
10. New Assemblies 10
11. Some Other Important Points 11

Introduction
Microsoft released ASP.NET 3.5 on November 19, 2007. Along with it, was released Visual Studio 2008. This evolution from ASP.NET 2.0 to ASP.NET 3.5 is quiet gradual. ASP.NET 3.5 uses the same engine as that of ASP.NET 2.0, with some extra features added on top of it. In this white paper, we will explore the new features added to ASP.NET 3.5.
New Features in ASP.NET 3.5

ASP.NET AJAX
In ASP.NET 2.0, ASP.NET AJAX was used as an extension to it. You had to download the extensions and install it. However in ASP.NET 3.5, ASP.NET AJAX is integrated into the .NET Framework, thereby making the process of building cool user interfaces easier and intuitive. The integration between web parts and the update panel is much smoother. Another noticeable feature is that you can now add ASP.NET AJAX Control Extenders to the toolbox in VS2008.

Even though this is an IDE specific feature, however I feel it deserves a mention over here for developers, who had to add extenders using source view earlier. It is also worth noting that Windows Communication Foundation (WCF) now supports JSON along with other standard protocols like SOAP, RSS and POX.

New Controls
The ListView and DataPager are new controls added along with a new datasource control called the LinqDataSource.



The ListView Control
The ListView control is quiet flexible and contains features of the GridView, DataGrid, Repeater and similar list controls available in ASP.NET 2.0. It provides the ability to insert, delete, page (using Data Pager), sort and edit data. However one feature of the ListView control that stands apart is that it gives you a great amount of flexibility over the markup generated. So you have a complete control on how the data is to be displayed. You can now render your data without using the
tag. You also get a rich set of templates with the ListView control.
Using the ListView for basic data display is very similar to using a Repeater. You have the ListView control and a set of templates that you can apply which include:
• LayoutTemplate
• ItemTemplate
• AlternatingItemTemplate
• SelectedItemTemplate
• EmptyItemTemplate
• EmptyDataTemplate
• ItemSeparatorTemplate
• GroupTemplate
• GroupSeparatorTemplate
• EditItemTemplate
• InsertItemTemplate
There are a few new ones here like GroupTemplate and InsertItemTemplate. InsertItemTemplate certainly is a nice addition so you can handle both editing and adding in the same space (previously with a DataGrid you had to insertion externally or insert data manually into a DataTable to display the empty row).

Playing around with this control feels nice in that you have all the control in the world to make it do what you want for rendering at the cost of a bit more markup code you have to create on your own. But personally I find that I struggle with DataGrid/GridView type issues anyway and think it's actually easier to put the layout together yourself and get really what you want rather than wade through abstracted properties 5 controls deep in GridView layout. It's much easier to create custom layouts for both display and editing.

Basic Data Display with the ListView
So to start off think of the ListView as a Repeater on steroids - everything is template driven including a 'master' layout template which is the layout template. For example a simple view might look like this:
DataSourceID="Data"
ItemContainerID="layoutTemplate"
DataKeyNames="Pk" >






<%# Eval("Name") %>

<%# Eval("EmpID") %>







DataPager (Adding Paging)
DataPager provides paging support to the ListView control. The best advantage is that you need not have to keep it ‘tied’ with the control on which the paging is being done. You can keep it anywhere on the page. DataPager gives you a consistent way of paging with the controls that support it. Currently only ListView supports it as it implements the IPageableItemContainer.

However support is likely to be added to other List controls as well. The pager also is an Inline element so it doesn't force any particular positioning on you - you can simply wrap it in a div to format it as you like.
To place a page I can use markup like this to put the pager anywhere on the page:

PagedControlID="lvItems" PageSize="5" >

PreviousPageText="..." />
LastPageText="Last"
NextPageText="Next" PreviousPageText="Previous" />




As you can see there are template fields inside of the DataPager so you can control the layout of the pager which is handy. The key to this control is the PagedControlID which points at a ListView. You specify a page size and that's all there's to it. You can also stick the Pager control into the Layout Template if you choose so the Pager can be a direct part of the generated output.

LINQ
LINQ (Language Integrated Query) adds native data querying capability to C# and VB.NET along with the compiler and Intelligence support. LINQ is a component of .NET 3.5. LINQ defines operators that allow you to code your query in a consistent manner over databases, objects and XML. The ASP.NET LinqDataSource control allows you to use LINQ to filter, order and group data before binding to the List controls.

In this white paper, I am going to explain you how to work with LINQ to SQL Classes and LinqDataSource control. For this, you will need .NET Framework 3.5, Visual Web Developer 2008, and SQL Server Express Database.

In order to work with LinqDataSource control, let’s create a database first.



Right click the App_Data folder and select Add New Item. Select SQL Server Database and click Add. Go to database explorer and explore the Database > Tables. Right click Tables and click Add New Table. Create following fields as displayed in the image below.




Now its time to create a LINQ to SQL classes. This can work as your Data Access Layer of the application. For this, right click the project folder in the solution explorer and select Add ASP.NET Folder and Select App_Code. Right click App_Code folder and select LINQ to SQL Classes and add it. You will see that you will have a DataClasses.dbml file into the App_Code folder.

Double click DataClasses.dbml to open it into Object Relational Designer (ORD) window. Now its time to drag the Address table into ORD from Database Explorer. Go to Database Explorer and drag the Address table to the ORD window. This will create two more file into App_Code related with DataClasses.dbml named DataClasses.dbml.layout and DataClasses.designer.cs or .vb depending upon what language you have selected and save DataClasses.dbml.




Till now we have created LINQ to SQL Classes and linked it with the database table. You can open DataClasses.designer.cs file and see what sorts of code have been generated automatically to deal with the Address database table.



Now we can link our LinqDataSource control with this LINQ to SQL Classes. To do that, create a new .aspx page, go to Design view and drag LinqDataSource control from data tab of the Toolbox.

Open the smart tag of LinqDataSource control and select Configure Data Source. In the Context Object list, select DataClassesDataContext from the dropdown and click next. Now select Addresses (Table
) from the table dropdown list and click Finish.

To allow manipulating the data of the database, again open the smart tag of the LinqDataSource control and select Enable Insert, Enable Delete and Enable Update checkboxes.




Now your LinqDataSource control is ready to be attached with any Data controls like GridView, ListView etc. Just drag a GridView from Data tab and specify the DataSource property to the LinqDataSource control. Run your .aspx page and you will see that your GridView is populating records from the database through LinqDataSource control efficiently and easily.



ASP.NET Merge Tool
ASP.NET 3.5 includes a new merge tool (aspnet_merge.exe). This tool lets you combine and manage assemblies created by aspnet_compiler.exe. This tool was available earlier as an add-on.
New Assemblies
The new assemblies that would be of use to ASP.NET 3.5 developers are as follows:

 System.Core.dll - Includes the implementation for LINQ to Objects
 System.Data.Linq.dll - Includes the implementation for LINQ to SQL
 System.Xml.Linq.dll - Includes the implementation for LINQ to XML
 System.Data.DataSetExtensions.dll - Includes the implementation for LINQ to DataSet.
 System.Web.Extensions.dll - Includes the implementation for ASP.NET AJAX (new enhancements added) and new web controls as explained earlier.



Some Other Important Points
 ASP.NET 3.5 provides better support to IIS7. IIS7 and ASP.NET 3.5 modules and handlers support unified configuration.
 You can have multiple versions of ASP.NET on the same machine.
 For those who are wondering what happened to ASP.NET 3.0, well there isn’t anything called ASP.NET 3.0.
 VS 2002 worked with ASP.NET 1.0, VS 2003 worked with ASP.NET 1.1, and VS 2005 worked with ASP.NET 2.0. However VS 2008 supports multi-targeting, that is it works with ASP.NET 2.0, and ASP.NET 3.5.







No comments: