I'm trying to create a helper that's compatible with Linq2Sql

The general idea of what I'm trying to do is this:

internal Expression<Func<TSource, Wrapper<TResult>>> Wrap<TSource, TResult>(Expression<Func<TSource, TResult>> dataSelector) where TSource : IHasOtherProperty { return (TSource data) => new Wrapper<TResult> { Entity = dataSelector(data), Extra = data.OtherProperty, }; }

So that I can call:

dataStore.Select(Wrap(query))

in places that I currently call

dataStore.Select(query)

Now this needs to be compatible with Linq2Sql, which means it needs to be done as an ExpressionTree.

I'm having trouble figuring out how to allocate the value of dataSelector to the Entity in an EntityFramework friendly manner

Below is the broken prototype: