BPM Runtime Error

I have some code that I entered in a BPM. When I check the syntax in the BPM it comes back all good. When I validate the BPM it comes back all good. I even do not run into trouble when saving it. But when I get the BPM to fire, I get this error.

Server Side Exception

BPM runtime caught an unexpected exception of 'NotSupportedException' type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail 
============
Description:  BPM runtime caught an unexpected exception of 'NotSupportedException' type.
See more info in the Inner Exception section of Exception Details.
Program:  System.Data.Entity.dll
Method:  Translate
Original Exception Type:  NotSupportedException
Framework Method:  C004_CustomCodeCondition
Framework Line Number:  151
Framework Column Number:  13
Framework Source:  C004_CustomCodeCondition at offset 685 in file:line:column Update.Pre.Cust_Hold.cs:151:13

Server Trace Stack:     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.TranslateExpression(Expression linq)
   at System.Data.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression 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.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.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
   at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
   at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.AggregateTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
   at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression 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<T>.GetEnumerator()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Epicor.Customization.Bpm.BO3B620D1AF1D74E6E92235625A378BAAA.UpdatePreProcessingDirective_Cust_Hold_2FC3146ED11845B08B390D0A4A2E9535.C004_CustomCodeCondition() in Update.Pre.Cust_Hold.cs:line 151
   at Epicor.Customization.Bpm.BO3B620D1AF1D74E6E92235625A378BAAA.UpdatePreProcessingDirective_Cust_Hold_2FC3146ED11845B08B390D0A4A2E9535.ExecuteCore() in Update.Pre.Cust_Hold.cs:line 80
   at Epicor.Customization.Bpm.DirectiveBase`3.Execute(TParam parameters) in c:\_Releases\ICE\3.1.600.0\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 129



Client Stack Trace 
==================
   at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
   at Ice.Proxy.BO.BpHoldsImpl.Update(BpHoldsDataSet ds)
   at Ice.Adapters.BpHoldsAdapter.OnDelete()
   at Ice.Lib.Framework.EpiBaseAdapter.Delete(DataRow dr)
   at Ice.UI.App.BpHoldsEntry.AttachTransaction.adapterDelete(DataRow dr)
   at Ice.UI.App.BpHoldsEntry.AttachTransaction.Delete()

Inner Exception 
===============
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

Has anyone ever seen anything like this? Not sure why it checks out fine in the BPM but errors out when it fires. When looking at the code in VS, the error is being called out on the first character (v) of the third line below.

private bool C004_CustomCodeCondition()
{
    var myID = (from thisHold in ttBpHoldAttachment select thisHold.HoldSysRowID);

int myCount = (from myHold in Db.BpHoldAttachment.With(LockHint.UpdLock) where
myHold.HoldSysRowID.ToString() == myID.ToString()
select myHold).Count();

if (myCount > 1)
{
return true;
}
else
{
return false;
}
}

_Inner Exception _
===============
LINQ to Entities does not recognize the method ‘System.String ToString()’ method,

This happened to me, Linq do not like the .ToString()…

So create string variables containing your .ToString() values and use the variables into the criteria.

Pierre

4 Likes

@Hogardy Thank you so much!!!

I read your response yesterday and I finally got my code to work. I am very remedial with my C# and while your response did not give me the exact answer to solve my problem, it pointed me in the right direction. Knowing that it was a limitation of how I was using LINQ, my brain finally got to creating my query with a Join instead of a Where clause. I really appreciate the help.

int myCount = (from myTT in ttBpHoldAttachment join
        myHold in Db.BpHoldAttachment.With(LockHint.UpdLock) on myTT.HoldSysRowID equals myHold.HoldSysRowID
        select myHold).Count();

When I try this I get a new exception:

The object cannot be attached because it is already in the object context. An object can only be reattached when it is in an unchanged state.

Incidentally, my code looks almost exactly like the code in this thread, however that thread had no replies and is too old to reply to.

Can you post your code? better yet start a new thread as this one is already marked as solved.