Compiling Dynamic Data Futures 3.5 SP1 in .NET 4

I use a custom ORM framework at work. Dynamic Data 4 requires Linq to SQL or Entity Framework to work out of the box. The way to work around this is to use DynamicObjectDataSource, available as part of Dynamic Data Futures VS2008 SP1 release on CodePlex. I downloaded and compiled the project in .NET framework 4. I got the following error:

The type or namespace name ‘NORTHWNDModel’ could not be found (are you missing a using directive or an assembly reference?)

The error is easily removed by deleting NORTHWNDModel and identifying the ObjectContext as NORTHWNDEntities. The namespaces for the model were changed a result of the conversion to the new framework. The next error was in Enumeration_Filter class:

The call is ambiguous between the following methods or properties: ‘Microsoft.Web.DynamicData.DynamicDataFutures.GetEnumType
(System.Web.DynamicData.MetaColumn)’ and ‘System.Web.DynamicData.DynamicDataExtensions.GetEnumType

The code:

private Type EnumType {
    get {
        if (_enumType == null) {
            _enumType = Column.GetEnumType();
        return _enumType;

GetEnumType is an extension method. I resolved this call to DynamicDataFutures.GetEnumType as follows:

_enumType = Microsoft.Web.DynamicData.DynamicDataFutures

The project compiled after resolving this error. I decided to test the DynamicDataClientSite by starting the Northwind Service and then browsing Default.aspx in a browser. This gave the following run-time exception:

Can’t find To column for column ‘ParentForInsert’.

When I reloaded the page, the error changed to:

There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages.

The model context NorthwindClientEntities is registered in the Global.asax.cs file. The error changed on reload because the context is registered only once on Application_Start when the Cassini web server starts up. Further requests to the web server gives the second error. To debug, I had to restart the server after every debug session. The source of the error lay in DataServiceModelProvider which used reflection to filter out the entity classes from the object context class properties by checking whether the property type has generic arguments.

public DataServiceModelProvider(Type contextType, Uri serviceRoot) {
    if (contextType == null) throw
                 new ArgumentNullException("contextType");
    if (serviceRoot == null) throw
                 new ArgumentNullException("serviceRoot");

    this.ContextType = contextType;
    this._serviceRoot = serviceRoot;

    object context = CreateContext();
    ContextType = context.GetType();

    var tables = new Collection();

    foreach (PropertyInfo prop in ContextType.GetProperties()) {
        if (prop.PropertyType.GetGenericArguments().Length != 1)

        tables.Add(new DataServiceTableProvider(this, prop));

    _tables = new ReadOnlyCollection(tables);

    foreach (var table in tables) {

The problem was that NorthwindClientEntities derive from DataServiceContext which has its own properties Links and Entities that are of generic type. These two get added into the table collection and cause the exception. I modified the code to exclude inherited properties:

foreach (PropertyInfo prop in ContextType.GetProperties()) {
   if (prop.PropertyType.GetGenericArguments().Length != 1
                         || prop.DeclaringType != ContextType)
   tables.Add(new DataServiceTableProvider(this, prop));

This solved the problem and I got the DataService and the client site working:

I then turned my attention to the DynamicDataFuturesSample and tried to run the Default.aspx page, which gave me the following Parser Error:

The server tag ‘asp:DynamicHyperLink’ is ambiguous. Please modify the associated registration that is causing ambiguity and pick a new tag prefix.

The reason for this and the previous error is that .NET 4 comprises its own version of some of the components of the Futures sample; in this case, DynamicHyperLink. The DynamicDataFutures project is referenced in the sample with ‘asp’ prefix. This can be changed in the web.config in the system.web > pages > controls element and then using the new prefix in the sample. Or, just remove the DynamicHyperLink class from the Futures project and use the .NET 4 version. I wanted to stick to the Futures components; so I changed the name of the class instead and use the new class name in the sample using search and replace.

The sample worked:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s