CompiledQuery problem with Query method

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

CompiledQuery problem with Query method

Post by crazypit » Fri 12 Mar 2010 09:16

Hello,

Is there CompiledQuery.Compile support for IQueryable objects returned by DataContext.Query method where the SQL is not a constant?

i.e.

I have the following scenario:

IQueryable udfValidationRules = UdfValidationRule.GetUdfsByRefType_2(dataContext, "1");

internal class UdfValidationRule
{


public static Func> GetUdfsByRefType_2 =
CompiledQuery.Compile(
(ExrayDataContext dataContext, string str) =>

dataContext.Query(@"select v.id validationRuleId, v.Notes notes ,v.severity validationRuleSeverity, v.if_cnd_id ifConditionId, v.then_cnd_id thenConditionId, e.value exprValue, null ifCondition, null thenCondition from validation_rules v, (select connect_by_root c.id RootId, c.id ParentId, level Hierarchy_Level " +
"from conditions c " +
"start with c.expr_id in (select a.id " +
"from expressions a " +
"where a.value like '%GetUdfValue(%' " +
"and a.type = " + str + ") " +
"connect by prior c.id = c.left_cnd_id " +
"or prior c.id = c.right_cnd_id) L ," +
"expressions e, " +
"conditions c " +
"where v.then_cnd_id = L.ParentId and v.status = 1 and v.ref_type = 1 " +
"and e.id = c.expr_id and c.id = L.RootId"));
}

I pass a String variable in order to be used in my SQL. When i run this, i get a "Non constant expressions is not supported for Query argument." with the following stack trace:

at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(LambdaExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.i(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.i(Expression A_0)
at Devart.Data.Linq.CompiledQuery.a(e A_0)
at Devart.Data.Linq.CompiledQuery.a(DataContext A_0, Object[] A_1)
at Devart.Data.Linq.CompiledQuery.Invoke[a,b,c](a A_0, b A_1)

crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Post by crazypit » Fri 12 Mar 2010 09:18

I'm using the latest stable version of dotConnect for Oracle.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 12 Mar 2010 15:20

Thank you for the report, I have reproduced the situation.
I will let you know about the results of our investigation.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 16 Mar 2010 12:41

There is no possibility to compile the query depending on a parameter.
Try the following workaround:

Code: Select all

internal class UdfValidationRule 
{ 

public static Func> GetUdfsByRefType_2 = 
CompiledQuery.Compile( 
(ExrayDataContext dataContext, string str) => 

dataContext.Query(@"select v.id validationRuleId, v.Notes notes ,v.severity validationRuleSeverity, v.if_cnd_id ifConditionId, v.then_cnd_id thenConditionId, e.value exprValue, null ifCondition, null thenCondition from validation_rules v, (select connect_by_root c.id RootId, c.id ParentId, level Hierarchy_Level " + 
"from conditions c " + 
"start with c.expr_id in (select a.id " + 
"from expressions a " + 
"where a.value like '%GetUdfValue(%' " + 
"and a.type = {0}) " + 
"connect by prior c.id = c.left_cnd_id " + 
"or prior c.id = c.right_cnd_id) L ," + 
"expressions e, " + 
"conditions c " + 
"where v.then_cnd_id = L.ParentId and v.status = 1 and v.ref_type = 1 " + 
"and e.id = c.expr_id and c.id = L.RootId", str)); 
}

Post Reply