0
votes

I have piece of code converted to C# in Epicor10. The on board compiler allows for this code, but when it is triggered from the API I receive:

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

I have it narrowed down to this part of my where clause:

&& string.Compare((string)Part_Row["ShortChar01"] ,(string)"None",true)!=0

it is part of this snippet:

 var ttRcvDtlRow = ttRcvDtl_iterator;
    foreach (var Part_iterator in (from Part_Row in Db.Part
                                   where string.Compare(Part_Row.Company, ttRcvDtlRow.Company, true) == 0
                                   && string.Compare(Part_Row.PartNum, ttRcvDtlRow.PartNum, true) == 0
                                   /*&& string.Compare((string)Part_Row["ShortChar01"] ,"None",true)!=0*/
                                                                     && string.Compare((string)Part_Row["ShortChar01"] ,(string)"None",true)!=0 
                                           select Part_Row))

Suggestions on how to fix. I understand from other posts that this happens b/c linq is sending this to SQL and there is a problem in the translating (or something similar)

Indexer?

Erp.Tables.Part Part;
foreach (var ttRcvDtl_iterator in (from ttRcvDtl_Row in ttRcvDtl
                               where (string.Equals(ttRcvDtl_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase) || string.Equals(ttRcvDtl_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase))
                               && String.IsNullOrEmpty(ttRcvDtl_Row.LotNum)
                               select ttRcvDtl_Row))

Thanks, JM

1
What is the type of Part_Row? And can you show the code of the indexer? There must be way to rewrite this into a FirstOrDefault(expression). - Gert Arnold
Please edit the question. Code in comments is hard to read. - Gert Arnold
Sorry new to this. - JMar
Should be there now in the right format - JMar
Try to replace Part_Row["ShortChar01"] by the LINQ statement in the indexer. It's hard to piece together what your code looks like without seeing the class model. Next question would be, what is ttRcvDtl? Etc. - Gert Arnold

1 Answers

0
votes

"I understand from other posts that this happens b/c linq is sending this to SQL and there is a problem in the translating"

That is exactly what's happening. EF doesn't know how to convert string.Compare into a SQL method.

&& string.Compare((string)Part_Row["ShortChar01"] ,(string)"None",true)!=0

should be

&& ((string)Part_Row["ShortChar01"]).ToLower() != "none"

Depending on your SQL Server settings, you don't even need the ToLower(), as you can set all string comparisons to be case insensitive by default.