Wednesday, December 19, 2007 #

Linq to Sql for other databases

The ADO.NET team blog have posted about a number of vendors who are currently working on Linq-to-sql providers for other databases, some of these include Oracle, Informix, Ingres, Sybase, MySQL, PostgreSQL, DB2, Progress and Microsoft SQL Server databases.

I won't be getting too excited as most of these more due to come within 3 months of the official VS2008 release. Come to think of it, I think this is when most vendors are planning to release new versions, including other cool plug-ins like Resharper.

posted @ Wednesday, December 19, 2007 7:26 AM | Feedback (0)

ASP.NET Databinding lazy properties

Every since using NHibernate, the effort required to use Many-to-many and one-to-many joins in business objects is a brainless exercise. When using a lazy loaded property on a business object, it just works, however, what happens when you try to bind this property using an ObjectDataSource hooked up to gridview or formview in asp.net...

image

As seen above, the GridView works out that it's out of it's depth with all the complex properties and only defines the simple text/int/boolean columns. The only alternative for the complex properties is to define your own template columns.

To display the value of a complex property you are still able to access the sub-properties using the Eval() command. So in the example below, I can use Eval() to display the name of the 'parent location' that is currently selected. To actually select the location, I can bind it the a custom user control using the Bind() method, this will pass in the entire lazy loaded 'Location' object. The user control must then pass back out a Location object when the ObjectDataSource needs to do an update.

image 

After making this change my grid now has the lazy loaded 'Parent Location' property:

image

When the grid is in action, view mode:

image

Edit mode:

image

Although this is a relatively simple example, it does show how much code you don't need to write to do a one-to-many join using binding in asp.net 2.0.

posted @ Wednesday, December 19, 2007 6:38 AM | Feedback (0)