The LINQ expression node type 'Invoke' is not supported

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
lbensch
Posts: 4
Joined: Wed 16 Mar 2011 08:16

The LINQ expression node type 'Invoke' is not supported

Post by lbensch » Wed 16 Mar 2011 08:34

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.

lbensch
Posts: 4
Joined: Wed 16 Mar 2011 08:16

Post by lbensch » Wed 16 Mar 2011 10:57

I forgot to specify that I use LinQConnect for Oracle.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 16 Mar 2011 15:41

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.

lbensch
Posts: 4
Joined: Wed 16 Mar 2011 08:16

Post by lbensch » Thu 17 Mar 2011 08:00

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:

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

Post by AndreyR » Thu 17 Mar 2011 14:27

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.

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

Post by AndreyR » Fri 18 Mar 2011 14:43

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.

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

Post by AndreyR » Tue 19 Apr 2011 12:25

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.

lbensch
Posts: 4
Joined: Wed 16 Mar 2011 08:16

Post by lbensch » Tue 19 Apr 2011 14:52

Thank you, I am in a hurry to have this version.

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

Post by AndreyR » Fri 22 Apr 2011 12:59

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.

Post Reply