Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

December 2009 - Posts

Using New ADO.NET Data Services Functionalities

In order to use the new functionalities (count, projections, server paging, for instance) supplied by version 1.5 of ADO.NET Data Services (see my previous post), you must explicitly enable them on the service side.

public static void InitializeService(DataServiceConfiguration config)
{
    config.EnableTypeConversion = true;
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    config.UseVerboseErrors = true;
    config.SetEntitySetAccessRule("*", EntitySetRights.All);
    config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
}

Note that you need to use the DataServiceConfiguration instead of the IDataServiceConfiguration interface, which was the one that the wizard previously declared.

Bookmark and Share
ADO.NET Data Services Update Released

A new version of the ADO.NET Data Services API was released, and you can get it from here, for the Windows 2000, Windows Server 2003, Windows XP, Windows Vista and Windows Server 2008, and from here, for Windows 7 and Windows Server 2008 R2.

Overview
The ADO.NET Data Services framework consists of patterns and libraries that enable the creation and consumption of REST-based data services for the web. This update to the Microsoft .NET Framework 3.5 SP1 provides additional features which extend the functionality provided in version 1.0 of the ADO.NET Data Services framework. The ADO.NET Data Services Update for .NET Framework 3.5 SP1 provides the following new features and improvements:

  • Built-in integration in Microsoft Office 2010 now makes it simple to expose Microsoft Office SharePoint Server data as a data service and access that data using the ADO.NET Data Services client library.
  • Custom Data Service Provider support now makes it easier to build an ADO.NET Data Service over any data source.
  • A new DataServiceCollection class has been added that supports rich two-way data binding. The new collection implements automatic change tracking on client side objects created using the ADO.NET Data Services client library.
  • Feed customization, provides a rich and flexible way to shape and modify the structure of ATOM feeds produced by an ADO.NET Data Service. Modifying the structure of the ATOM feed produced by the ADO.NET Data Services makes it possible for third-party clients that can consume an ATOM feed in a custom format to consume feeds from an ADO.NET Data Service.
  • Enhanced blob support for streaming large binary objects to/from a data service. Support has also been added to the ADO.NET Data Services client library to provide the ability to upload and download binary objects (such as: images, videos, documents, etc.) from an application created using the library.
  • Server-driven paging allows a service author to limit the size of the result set returned by a query; this gives the service author a new level of control over the network bandwidth and computation time required to process any request.
  • A new select query option allows the result of a query to be projected into an arbitrary type; projecting gives the client the ability to request a specific set of properties of an entity. Reducing the number of properties requested in a query reduces processing time and network bandwidth for the request.
  • The option to request a count of the number of entities in a set and the option to include the total count of the number of entities in the set when a query returns a partial result.
  • Request pipeline improvements give the service author greater control and customization ability over various stages of query processing.

You can get more information from the Astoria blog.

In order to use it, you must specify the new version in the InitializeService method, which requires that you switch the parameter type from IDataServiceConfiguration to DataServiceConfiguration:

public static void InitializeService(DataServiceConfiguration config) 
{
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
Bookmark and Share
HTML 5 Support in IE8

A nice post: IE8 and HTML 5

Bookmark and Share
Posted: Dec 16 2009, 10:54 AM by Ricardo Peres | with no comments
Filed under: ,
Nested Master Pages

In ASP.NET 2.0+ you can have nested master pages. In Visual Studio 2008, the editor even knows how to handle them properly.

Nested master pages allows specializing the original master page, for example, entering Contents for some of the ContentPlaceHolders. The problem is, when we are using a nested master page, we can no longer access the original master page's ContentPlaceHolders. The trick is, on the nested master page, to create additional Contents and inside them create new ContentPlaceHolders with the same names as the parent master page's.

<%@ Master Language="C#" CodeBehind="Site.master.cs" Inherits="Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>
		<asp:ContentPlaceHolder ID="title" runat="server"/>
    </title>
</head>
<body>
    <form runat="server">
        <asp:ContentPlaceHolder ID="content" runat="server"/>
    </
</body>
</html>

<%@ Master Language="C#" MasterPageFile="~/Site.Master" CodeBehind="Admin.master.cs" Inherits="Admin" %>
<asp:Content runat="server" ContentPlaceHolderID="title">
	<asp:ContentPlaceHolder runat="server" ID="title" />
</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="content">
        <span>Some content</span>
	<asp:ContentPlaceHolder runat="server" ID="content" />
</asp:Content>
Bookmark and Share
Posted: Dec 11 2009, 03:05 PM by Ricardo Peres | with no comments
Filed under: ,
ListBoundField and ResourceBoundField

Following my previous post on the ForeignKeyBoundField, here are some more templates for your GridView or DetailsView controls: ListBoundField and ResourceBoundField.

ListBoundField converts a value coming from a data source in a string, supplied in a list in the markup. ResourceBoundField translates a value by using a resource file, in a way identical to the one used by the <%$ Resource > expression builder.

Using these two templates, you can change the value displayed on the grid or details without any trouble.

If you like them, want to change them, or need an additional feature, drop me a line.

Bookmark and Share
Posted: Dec 11 2009, 11:02 AM by Ricardo Peres | with no comments
Filed under: ,
ForeignKeyBoundField

When working with GridView and DetailsView controls, we must specify the columns we want to include, by adding field templates to the Columns and Fields collections. These field templates are bound to a specific property of a data source, which, typically, comes from a database table.

ASP.NET comes with a number of field templates (from the MSDN documentation):

Column field type Description
BoundField Displays the value of a field in a data source as text.
ButtonField Displays a command button in a data-bound control. Depending on the control, this allows you to display either a row or a column with a custom button control, such as an Add or a Remove button.
CheckBoxField Displays a check box in a data-bound control. This data control field type is commonly used to display fields with a Boolean value.
CommandField Displays built-in command buttons to perform edit, insert, or delete operations in a data-bound control.
HyperLinkField Displays the value of a field in a data source as a hyperlink. This data control field type allows you to bind a second field to the hyperlink's URL.
ImageField Displays an image in a data-bound control.
TemplateField Displays user-defined content in a data-bound control according to a specified template.

Of course, one can think of additional field templates, for example, one that would allow picking a value from another table, to which the main table is connected by a foreign key. I wrote one such template and named it ForeignKeyBoundField, and you can download the code from this post.

It must be declared, either on the DetailsView or GridView control, in the same way as a BoundField would, but with some additional properties:

<asp:DetailsView runat="server" ...>

<Fields>

<asp:BoundField DataField="SomeColumn" HeaderText="Some Column"/>

<asp:ForeignKeyBoundField DataField="SomeOtherForeignKeyColumn" HeaderText="Some Other Column" ForeignEntityName="SomeOtherColumn" ForeignEntityDisplayField="SomeOtherDisplayColumn"/>

</Fields>

</asp:DetailsView>

On the ForeignKeyBoundField declaration you specify the name of an additional table which contains the column you want to display and the actual column. The two tables must be linked by the column which is equal to the content of the DataField property.

Instead of a plain text label containing the foreign key, the ForeignKeyBoundField displays the column from the associated table, and, when in edit or insert mode, displays a DropDownList allowing the selection of a value by a more meaningful column than just its id. You can see an example of th the picture below, with a DetailsView control.

DetailsView

In order for it to work, a SqlDataSource, LinqDataSource or EntityDataSource data source controls must be used, it won't work with ObjectDataSource, XmlDataSource or AccessDataSource.

As always, hope this comes in handy, it sure did to me!

Bookmark and Share
Posted: Dec 10 2009, 09:29 PM by Ricardo Peres | with 2 comment(s)
Filed under: ,
New Version of Visual NHibernate

A new version was released: 2.0.9.1018. Some of my suggestions have been implemented, more to come (I hope!). You can contribute by giving feedback at the forum, which is located here.

Read the change log here and download it here.

Bookmark and Share
Security Lessons from How Windows Live Uses ASP.NET MVC

Nice whitepaper, available here.

Bookmark and Share
Dynamic LINQ

Updated: Dynamic LINQ in an Assembly Near By

Included with Microsoft's .NET samples, which you can get here lies an hidden gem: a set of method extensions for IQueryable and IQueryable<T> that allow execution of lambda expressions specified as strings, which is handy if you want to generate expressions dynamically.

The actual code is in the CSharpSamples\LinqSamples\DynamicQuery folder. I think Microsoft could have arranged it slightly better, in order to promote quicker reuse, but probably that wasn't on their minds. The extensions are offered by class DynamicQueryable and consist of:

  • GroupBy
  • OrderBy
  • Select
  • Skip
  • Take
  • Where

There are also other useful classes, like DynamicExpression, which parses a String into a lambda.

With these, you can do things like:


Func<SomeClass, Boolean> filterExpression = DynamicExpression.ParseLambda<SomeClass, Boolean>("SomeProperty == true && SomeOtherProperty > 10");  //create lambda from string
var list = dataSource.OrderBy("PropertyName").Take("10").Skip("1").ToList();  //string instead of lambda

For your convenience, I attach a DLL which only contains the reusable parts of the project, in the System.Linq.Dynamic namespace. I have been using this, and I find it very helpful, have a look at it, and happy dynamic LINQing!

Bookmark and Share

Posted: Dec 03 2009, 12:15 PM by Ricardo Peres | with 19 comment(s)
Filed under: ,
Visual NHibernate

The guys at Slyce Software have released Visual NHibernate Beta. It is still far from final, but it looks promising. You can get it from here, there are also some screenshots.

So far, I have noticed some things missing. There is a discussion going on at the nhusers mailing list about it, but here are my 50 cents, in no particular order:

  • Support for additional databases, starting with Oracle
  • Optional support for generating partial classes
  • Inclusion of the Serializable attribute
  • Support for lazy loading of relational properties
  • Allow specifying non-public setters
  • Configuration of id generators
  • Removal of mapping table from the model, in many-to-many relationships, when there are no additional attributes in the relation
  • Generating composite keys in a new class, instead of having multiple properties

More news in the next days.

Bookmark and Share

More Posts