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)
CompiledQuery problem with Query method
There is no possibility to compile the query depending on a parameter.
Try the following workaround:
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));
}