On Jun 29, 4:50 pm, Giacomo Tesio <[email protected]> wrote:
> AFAIK, you should build the lambda to be passed to the Select().
>
> This should not be too complex, something like:
> PropertyInfo property = typeof(T).GetProperty(propertyName);
> ParameterExpression p = Expression.Parameter(typeof(T), "p");
> Expression body = Expression.MemberAccess(p, property);
> LambdaExpression forSelect = Expression.Lambda(body, p);
>
> This, passed to the Select() method, should be what you need.
>
> BTW, let me say that I do not see any reason to use such method, unless you
> *really* need to optimize the bandwith between your rdbms and the
> application server...
>
> Giacomo
Hi Giacomo,
Thanks very much for the reply.
In this case I have a table which has one column that can contain up
to 30k bytes. There are other columns in the table that I need to
check and update without pulling down the whole row every time and
potentially having to transfer 30k bytes back and forth for nothing.
Unfortunately my lambda expertise isn't up to scratch and I'm
struggling to adopt the approach you've suggested.
I've gotten to:
string dynamicProperty = "MyProperty";
PropertyInfo property = typeof(T).GetProperty(dynamicProperty);
ParameterExpression p = Expression.Parameter(typeof
(T),dynamicProperty);
Expression body = Expression.MakeMemberAccess(p, property);
LambdaExpression forSelect = Expression.Lambda(body, p);
var query = (from item in table select forSelect);
var result = query.First();
Console.WriteLine("result=" + result);
When executing I get an exception of "Unable to cast object of type
'System.Byte[]' to type 'System.Linq.Expressions.LambdaExpression'".
The SQL query generated by DbLinq is:
SELECT ?forSelect
FROM mytable
LIMIT 1
-- ?forSelect [ MyProperty => MyProperty.MyProperty]
Thanks,
Aaron
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---