Skip to content

Custom order for LINQ Query #3586

Closed Answered by nfplee
nfplee asked this question in Q&A
Discussion options

You must be logged in to vote

I've come up with the following HQL Generator to achieve this:

public class IndexOfHqlGenerator : BaseHqlGeneratorForMethod {
    public IndexOfHqlGenerator() {
        SupportedMethods = [
            ReflectHelper.GetMethodDefinition<IList<int>>(x => x.IndexOf(0)),
            ReflectHelper.GetMethodDefinition<List<int>>(x => x.IndexOf(0))
        ];
    }

    public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) {
        var collection = (IList<int>)((ConstantExpression)targetObject).Value!;
        var value = visitor.Visit(arguments[0]).AsExpression();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nfplee
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants