DataSource Query Extender in Dynamic Data Preview 4
One of the new big features in ASP.NET 4 is the QueryExtender control. This control allows very simple filtering for data source controls for common operations that developers want to do like search for a string across columns, check if the value of a column is in a certain range and other operations. These samples also show the DomainDataSource which is a new ASP.NET data source control that will be used to access .NET RIA Service Domain Services. See the .NET RIA Service section at the bottom of the document for how to download and install the tooling support for Domain Services.
· DomainDataSource
· Basic. This show typical ASP.NET data binding using the DomainServiceDataSource.
· With QueryBlock. This demonstrates all the new filters that are possibly with the QueryExtender which include search, range, control and custom.
· Validation and Authentication. This demonstrates support for validation and user authentication in Domain Services and that the DomainDataSource supports these scenarios.
· LinqDataSource
ADO.NET DataServices
This project contains a sample DataServiceLinqDataSource which is an ASP.NET data source for accessing ADO.NET Data Services from web pages.
· Microsoft.Data.Services.WebControls. This project contains a standalone ASP.NET datasource that can be used to access ADO.NET Data Services. It also contains a data model provider for using ADO.NET Data Services from Dynamic Data.
· DataServiceClient. This is a Dynamic Data application that scaffolds an ADO.NET Data Service.
DataServiceServer. This is a sample ADO.NET Data Service used as the server for the DataServiceClient sample.
Dynamic Data Futures
This project contains some samples of features and techniques that will not be shipping in .NET 4 but may show up in future releases of Dynamic Data.
· Set Metadata at Runtime. Normally metadata that Dynamic Data consumes is created at compile time using attributes. This sample shows how to add metadata to a data model at runtime.
· Image FieldTemplates. This field template sample shows how to take columns in the database that contain binary images and allow them to be displayed and edited using the DbImage field template. It also supports columns that contain URL’s to images via the FileImage field template. Both of these can be applied to columns using the UIHint attribute.
· Pretty URL’s. This demonstrates how to build routes that contain one or more primary keys and format them into a pretty urls. For example: /Categories/Details?CategoryID=3 to show as /Categories/Details/3
· Project Templates
These are starter projects that can be used to build brand new applications that have support for all the new features in the Preview. To start just copy the directory that supports the data model that you are using to a working folder, create the data model and register it in Global.asax.
· DomainServiceProject. This is for projects using the .NET RIA Domain Service for the data access layer. See the section below on .NET RIA Services for information on how to get tooling support for creating data access layers.
· EntityFrameworkProject. This is for projects using Entity Framework models for the data access layer.
· LinqToSqlProject. This is for projects using Linq to SQL for the data access layer.
Posted in: C# and .NET| Tags: CTP Dynamic Data DataSource Query Query Extender DataServices FeatureSeveral New Features in Dynamic Data Preview 4
· Entity Templates
· Filters
· Support for inheritance in Entity Framework and Linq to SQL
· Support for many to many in Entity Framework
· Email and Url field templates
· Support for many new data annotation attributes
· Display
· Order – control order of fields
· AutoGenerateFilter - control if a field is used as a filter
· FilterUIHint – override default filter used for a field
· Ability to provide default values for fields at runtime
· Ability to use field templates and validation in Web pages hosted by any ASP.NET application.
· Requires no data model
· Requires no routing
· Datasource for accessing .NET RIA Domain Service and Dynamic Data support for .NET RIA Domain Service
DynamicDataSamples
This is the primary project sample that shows most of the new functionality that has been added to Dynamic Data since .NET 3.5 SP1. The default.aspx page highlights many of the new items that are being added in .NET 4, in particular:
· Filter Templates. Filters are now first class citizens in Dynamic Data. There is a new FilterTemplate directory that contains the default filter templates and supports user defined filter templates. Filters can be applied to columns using the new FilterUIHint attribute.
· Entity Templates – The Details, Edit and Insert page templates in version 1.0 forced a two column display style (field name, field value). Entity templates allow for the layout of an entity to be arbitrarily customized.
· Field Templates. The following new field templates have been created.
· Email Field Template. Data fields in the model that are marked with DataType(DataType.Email) will be displayed as mailto: hyperlinks that will launch the email client when clicked.
· Url Field Template. Fields in the model that are marked with DataType(DataType.Url) will be displayed as hyperlinks that will open a new window with the given URL.
· Many to Many Relationships in Tables. Entity Framework models support many to many relationships. Dynamic Data will display these as a list of values or in edit mode a list of checkboxes for the selectable columns.
· Enumeration on Model. If a column in the model is associated with an enumeration data type it will be displayed as a dropdown list of the values from the enumeration.
· Enumeration using Metadata. If a column in the model has an EnumDataType(typeof(enum)) attribute it associated with an enumeration data type it will be displayed as a dropdown list of the values from the enumeration.
· Inheritance. Both Entity Framework and Linq to SQL support inheritance relationships in their data models. Dynamic Data will now properly display this data.
This sample also shows some other advanced features in Dynamic Data such as
· Multiple Data Models
· Each data model uses a different data model technology.
· Each registers its own custom DynamicData directory.
Posted in: C# and .NET| Tags: NET CTP .NET 4.0 New Dynamic Data Control field data framework entity support filter order dynamicHow to: Enable Local Cache (Code) (Velocity)
To programmatically enable local cache when creating your cache client, you must make sure the localCache parameter in the DataCacheFactory class constructor is equal to true. For more information about the application configuration settings, see Application Configuration Settings (Velocity).
Note
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)
To create a cache client that has local cache enabled
Create an array of DataCacheServerEndPoint objects to specify the cache hosts for the client.
Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor. Note: For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.
Configure your cache client type by assigning a true or false value to the routingClient parameter of the DataCacheFactory constructor. Use the true value for a routing client, or a false value for a simple client.
Enable local cache by assigning a true value to the localCache parameter of the DataCacheFactory constructor.
(optional) Configure your cache client for cache notifications by using the DataCacheFactory constructor with the following additional parameters.
syncPolicy: Use the DataCacheLocalCacheSyncPolicy enumeration to choose how locally cached objects are invalidated. Use TimeoutBased to indicate that a time-out value should be used or NotificationBased to indicate that cache notifications will be used. For more information, see Cache Clients and Local Cache (Velocity).
localCacheTimeout: Use this parameter to specify the number of seconds that an object will remain in local cache before it is invalidated. This parameter is ignored if syncPolicy is set to NotificationBased.
pollInterval: Use this parameter to specify the interval of frequency, in seconds, that the cache client will check with the cache cluster for cache notifications. The default value is 300 seconds. Note: Local cache is not required for cache notifications. For more information, see Cache Notifications (Velocity).
Use the GetCache method to obtain an instance of the routing client.
Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Application Configuration Code client parameter enable local localcacheHow to: Get Started with a Simple Client (Code) (Velocity)
When you programmatically configure your cache client, the configuration settings are passed to the DataCacheFactory class constructor.
Note
For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.
The cache client type is defined by the routingClient parameter in the DataCacheFactory class constructor. For a simple client, the routingClient parameter must be false. For more information about the application configuration settings, see Application Configuration Settings (Velocity).
Note
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)
To configure a simple client programmatically
Create an array of DataCacheServerEndpoint objects to specify the cache hosts for the client.
Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor.
Select a simple client type by assigning a false value to the routingClient parameter of the DataCacheFactory constructor.
Configure local cache by assigning a true or false value to the localCache parameter of the DataCacheFactory constructor. Use the true value to enable local cache or a false value to disable local cache.
Use the GetCache method to obtain an instance of the routing client.
Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Configuration Code client class datacachefactory constructor configure simpleHow to: Get Started with a Routing Client (Code) (Velocity)
When you programmatically configure your cache client, the configuration settings are passed to the DataCacheFactory class constructor.
Note
For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.
The cache client type is defined by the routingClient parameter in the DataCacheFactory class constructor. For a routing client, the routingClient parameter must be true. For more information about the application configuration settings, see Application Configuration Settings (Velocity).
Note
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)
To configure a routing client programmatically
Create an array of DataCacheServerEndpoint objects to specify the cache hosts for the client.
Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor.
Select a routing client type by assigning a true value to the routingClient parameter of the DataCacheFactory constructor.
Configure local cache by assigning a true or false value to the localCache parameter of the DataCacheFactory constructor. Use the true value to enable local cache, or a false value to disable local cache.
Use the GetCache method to obtain an instance of the routing client.
Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Configuration Code client class datacachefactory constructor configure routingHow to: Remove an Object from Cache (Velocity)
The following examples show the ways you can remove objects from the cache. These procedures assume that you have already set up your cache cluster and have prepared your development environment to write cache-enabled applications. For more information about how to do this, see Installation and Deployment (Velocity) and How to: Prepare the Development Environment (Velocity).
For more details about the methods that are used in these examples, see these class library topics:
Remove
Item
Data in the cache is not encrypted and is available to any cache client with the appropriate configuration settings. We highly recommend that you secure the XML-based application configuration files, if used, to specify the cache client.
To remove an object from the cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.
Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.
Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.
After you have the DataCache object, the Remove method or Item property may be used to remove an object from cache.
Example
The following example uses the Remove method to remove an object from cache.
Note
There are many other parameters available for this method. See the Remove class library for more information.
C# Copy Code
//remove object in cache using key "Key0"
myCache.Remove("Key0");
The following example uses the Item property that has array notation to remove an object from cache.
C# Copy Code
//remove object in cache using array notation
myCache["Key0"] = null;
How to: Get an Object from Cache (Velocity)
The following examples show the ways you can retrieve objects from the cache. These procedures assume that you have already set up your cache cluster and have prepared your development environment to write cache-enabled applications. For more information about how to do this, see Installation and Deployment (Velocity) and How to: Prepare the Development Environment (Velocity).
For more details about the methods that are used in these examples, see these class library topics:
Get
Item
Data in the cache is not encrypted and is available to any cache client with the appropriate configuration settings. We highly recommend that you secure the XML-based application configuration files, if used, to specify the cache client.
To get an object from the cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.
Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.
Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.
After you have the DataCache object, the Get method or Item property may be used to retrieve an object from cache.
Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 MicrosoftHow to: Update an Object in Cache (Velocity)
To update an object in cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.
Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.
Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.
After you have the DataCache object, the Put method or Item property may be used to update an object in cache.
Example
The following example uses the Put method to add an object to cache. If the object is not present when this method is called, it will be added to the cache. If the object is already present, it will be replaced.
Note
There are many other parameters available for this method. See the Put class library for more information.
C# Copy Code
//add or replace object in cache using key "Key0"
myCache.Put("Key0", "object replaced or added using Key0");
The following example uses the Item property that has array notation to add an object to cache. If the object is not present when this method is called, it will be added to the cache. If the object is already present, it will be replaced.
C# Copy Code
//add or replace object in cache using array notation
myCache["Key0"] = "object replaced or added using Key0";