Page 1 of 1

The LINQ expression node type 'Invoke' is not supported

Posted: Wed 16 Mar 2011 08:34
by lbensch
Hello, I do not know if I am in the good section, but I have worries with DevArt.
I would wish to make a “generic” function allowing to manage the character “%” in my research.
It is necessary that this function is generic because it can apply to any column.
Moreover, it is not sensitive case.
With this intention, I have to create this one:

Code: Select all

static IQueryable CritereString(IQueryable list, Func func, string value)
{
    if (value.StartsWith("%") && value.EndsWith("%"))
    {
        value = value.Substring(1, value.Length - 2);
        return list.Where(rp => func(rp).ToUpper().Contains(value));
    }
    if (value.StartsWith("%"))
    {
        value = value.Substring(1, value.Length - 1);
        return list.Where(rp => func(rp).ToUpper().EndsWith(value));
    }
    if (value.EndsWith("%"))
    {
        value = value.Substring(0, value.Length - 1);
        return list.Where(rp => func(rp).ToUpper().StartsWith(value));
    }
    return list.Where(rp => func(rp).ToUpper() == value);
}
I call this function in the following way:

Code: Select all

...
var list = Entities.Patients.AsQueryable();
list = CritereString(list, rp => rp.Nom, (string)critere.Value);
...
If you could help me, it would be brilliant, because I have about fifty requests similar to convert and I badly see myself seizing 50 times the same end of code.

Posted: Wed 16 Mar 2011 10:57
by lbensch
I forgot to specify that I use LinQConnect for Oracle.

Posted: Wed 16 Mar 2011 15:41
by StanislavK
Apparently, the problem is that the 'func' custom method is used in the predicate of the Where method, which is not allowed since custom methods cannot be translated to SQL. To pass a delegate that should be used, e.g., in the Where method, an Expression object should be used instead:
http://msdn.microsoft.com/en-us/library ... ssion.aspx

As far as I can understand, you've tried to implement the 'LIKE' SQL condition. Am I correct? To include the 'LIKE' condition into your queries, you can use the static SqLMethods.Like method, e.g.

Code: Select all

var list = Entities.Patients
  .Where(rp => 
    SqlMethods.Like(rp.Nom.ToUpper(), (string)critere.Value));
Please tell us if this helps.

Posted: Thu 17 Mar 2011 08:00
by lbensch
I try your solution, but I have this message :

System.NotSupportedException was caught
Message=LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method, and this method cannot be translated into a store expression.
Source=System.Data.Entity
StackTrace:
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Infologic.Sante.SGL.Genno.Commun.Assistants.ChercherPatientCommun.CreerFiltreStrict(IEnumerable`1 listOriginale, IEnumerable`1 criteres) in N:\01.SGL\03.IHM\Commun\Assistants\ChercherPatientCommun.cs:line 385
at Infologic.Sante.SGL.Genno.Commun.Assistants.ChercherPatientCommun.ChercherPatientCommunChercherClick(Object pSender, EventArgs e) in N:\01.SGL\03.IHM\Commun\Assistants\ChercherPatientCommun.cs:line 184
at Infologic.Sante.Librairie.IHM.EtapeChercherAssistant.FBackroundChercherDoWork() in N:\00.Librairie\03.IHM\EtapeChercherAssistant.cs:line 691
InnerException:

Posted: Thu 17 Mar 2011 14:27
by AndreyR
Thank you for the report, we are investigating the situation.
I will let you know about the results of our investigation.

P.S. I have moved this topic to the "Entity Framework support" forum.

Posted: Fri 18 Mar 2011 14:43
by AndreyR
We have added a UserVoice suggestion about the "LIKE" implementation.
You can vote for this and other suggestions here, and add new suggestions as well.

Posted: Tue 19 Apr 2011 12:25
by AndreyR
A new Beta build containing an OracleFunctions.Like implementation will be available this month. It will be available both for LINQ to Entities and Entity SQL.

Posted: Tue 19 Apr 2011 14:52
by lbensch
Thank you, I am in a hurry to have this version.

Posted: Fri 22 Apr 2011 12:59
by AndreyR
The latest 6.30.145 Beta build of dotConnect for Oracle can be downloaded from here (the trial version) or from Registered Users' Area (provided that you have an active subscription).
For more information about the fixes and improvements available in dotConnect for Oracle Beta, please refer to
this post.