So far, I find Linq can be used on existing fields and properties of a class, not on virtual properties. In other words, ITypedList can not work with Linq, even by dynamic Linq.
I tried the following code:
IQueryable contact ; ...
dynamic l = contact.Select("Customer.Name as Name");
// Customer is a virtual property provided by the interface of ITypedList.
Then, I met the exception of "No linkedPropertyName or field 'Customer' exists in type 'Contact'".
I traced into dynamic Linq and found the following code raised the exception:
MemberInfo member = FindPropertyOrField(type, id, instance == null);
if (member == null)
throw ParseError(errorPos, Res.UnknownPropertyOrField,
id, GetTypeName(type));
return member is PropertyInfo ?
Expression.Property(instance, (PropertyInfo)member) :
Expression.Field(instance, (FieldInfo)member);
in the method of Expression ParseMemberAccess(Type type, Expression instance).
It is obvious only real member of fields and properties are supported in Linq.
But I still expect someone may have found a way to do Linq on virtual properties.
If you find a way to do so, please share your experience.
Thank you in advance,
Ying