Question

I can generate the following SQL:

[dbo].[CategoryMatch]([CategoryId], ???) = 1

With the following HQL generator:

treeBuilder.Equality(treeBuilder.MethodCall("[dbo].[CategoryMatch]", new[] {
    visitor.Visit(arguments[0]).AsExpression(),
    visitor.Visit(arguments[1]).AsExpression()
}), treeBuilder.Constant(1));

However I've found this doesn't perform aswell as saying:

[CategoryId] IN (SELECT [Id] FROM [dbo].GetCategories(???))

How could I adapt my HQL generator above with the new SQL? I'd appreciate the help. Thanks

Update:

So far I've come up with the following:

treeBuilder.In(
    visitor.Visit(arguments[0]).AsExpression(),
    treeBuilder.SelectFrom(
        treeBuilder.From(
            treeBuilder.Range(
                treeBuilder.MethodCall("[dbo].[GetCategories]", new[] {
                    visitor.Visit(arguments[1]).AsExpression()
                }).AsExpression(),
                treeBuilder.Alias("c")
            )
        )
    )
);

But this gives the error:

Specified method is not supported.

Was it helpful?

Solution

I've managed to come up with the following:

treeBuilder.In(
    visitor.Visit(arguments[0]).AsExpression(),
    treeBuilder.MethodCall("SELECT [Id] FROM [dbo].[GetCategories]", new[] {
        visitor.Visit(arguments[1]).AsExpression()
    }).AsExpression()
)

It's abit of a hack but it works so I guess it will do for now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top