c# - Resolving method overload among LINQ query methods -


So, the context of this question is very specific, but I think that a normal C # The question is. :)

I have an ASP.NET web form page that has a restricted gridvoice control for an ObjectDataSource. Data source control data is linked to Access Class, which, in turn, uses LINQ to query unit framework v4. Data Access Class methods have sorting / paging criteria, so I can use the built-in capabilities of Gridview / ObjectDataSure controls. Here's an example:

  Public ILIT  

Because the sort expression that has passed this method by grid view control is a string, then call OrderBy to be dynamic is required. For this, I am using Nifty

The problem is that OrderBy is overloaded here, and two of the loads are effectively the same signature.

  Get ObjectQuery & lt> T & gt; OrderBy (String keys, parameter ObjectParameter [] parameter)  

(from System.Data.Entity)

  IQueryable OrderBy (this IQueryable source, string command, The absolute object [] value)  

(from dynamic LINQ assistive classes)

The C # compiler resolves the first method (either because it is giving priority to non Is the -extension method, or because the first method is not about a square one interface, or some other resolution argument I'm thinking of), which does not work on:

EntitySqlException: 'Id' can not be resolved in the current region or context.

?

I know that I can do this:

  back _db.Pople Encodable () .interbay (! String.IsNullOrWhiteSpace (sortExpression) Sorting: "ID"). Exclude (starting line). (Ma XimumRows) .Olist ();  

But that makes my data access methods a bit useless. I can also go into the dynamic LINQ code and orderByDynamic to orderBy (eliminating the need to resolve some) Can change the name of, but I would not like to do so, either

Any other ideas? Thanks!

Either because it prefers non-extension method

< / Blockquote>

This is the correct hypothesis, the example methods of a class are preferred over an extension method. You have already diagnosed the possible means of getting around it. Another option is to call the extension method directly (because it is just a method in a stable class).


Comments