PC Review


Reply
Thread Tools Rate Thread

ambiguous match exception in Marc Dynamic Query order method

 
 
Andrus
Guest
Posts: n/a
 
      27th Jun 2008
My entity contains properties which are different only by case.

I tried to use Marc Dynamic Order but in this case line in method
UtilityOrderBy<T>()

MemberExpression member = Expression.Property(param, propertyName);

causes AmbiguousMatchException

How to change method below so that
Expression.Property(param, propertyName)

does not ignore case ?

Should I get PropertyInfo from T and use Property() overload with takes
PropertyInfo parameter ?

Andrus.

static IOrderedQueryable<T> UtilityOrderBy<T>(
IQueryable<T> query, string propertyName, MethodInfo method) {
// crete a property-getter expression
ParameterExpression param = Expression.Parameter(typeof(T), "p");

// this causes Ambiguous match exception :
MemberExpression member = Expression.Property(param, propertyName);
object[] reflArgs = { query, member, param };
// invoke the specified method (for the appropriatePropertyType)
return (IOrderedQueryable<T>)method.MakeGenericMethod(
typeof(T), ((PropertyInfo)member.Member).PropertyType)
.Invoke(null, reflArgs);
}

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Jun 2008
On Jun 27, 1:50*pm, "Andrus" <kobrule...@hot.ee> wrote:
> My entity contains properties which are different only by case.


Ick. That's really nasty. Is there any way to avoid it? It's a recipe
for bugs, IMO.

> I tried to use Marc Dynamic Order but in this case line in method
> UtilityOrderBy<T>()
>
> MemberExpression member = Expression.Property(param, propertyName);
>
> causes AmbiguousMatchException
>
> How to change method below so that
> *Expression.Property(param, propertyName)
>
> *does not ignore case ?


Use the overload of Expression.Property which takes a PropertyInfo.
Find the PropertyInfo by using Type.GetProperty on the appropriate
type.

Jon
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ambiguous match found aparna Microsoft ASP .NET 4 26th Mar 2008 11:28 AM
Form won't match query sort order TomK via AccessMonster.com Microsoft Access Forms 2 16th Nov 2007 04:39 PM
Ambiguous Match Exception--Help Please ECathell Microsoft VB .NET 0 12th Oct 2005 08:24 PM
Ambiguous match found. Ben Microsoft ASP .NET 3 28th Apr 2005 10:17 AM
Specify Sort Order in Dynamic Query MaryAnn Microsoft Access Queries 1 14th Jan 2004 05:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:55 AM.