views:

17

answers:

0

I'm porting a Dynamic Data project from L2S with DD preview 4 to EF with .NET 4. My custom code which works with MetaTable.GetQuery() results has stopped working. I have used the following code to apply ordering/filtering expressions to the MetaTable contents:

public static IEnumerable GetOrderedItems(this MetaTable table)
{
    var query = table.GetQuery();
    return (IEnumerable)query.Provider.Execute(ApplyOrdering(query.Expression));
}

Now query.Provider.Execute throws

The specified cast from a materialized 'Model.Company' type to the 'System.Data.Objects.ObjectQuery`1[Model.Company]' type is not valid.

I can get the unmodified result with just return query;, but I get the exception with even query.Provider.Execute(query.Expression). How can this code be fixed? Or maybe there is a more proper way to make a query consisting of the MetaTable main query and some dynamically chained expressions (such as Single, Where or Order)?