E9 to E10 BPM code conversion problem

Just to close the loop, it was a conversion issue, not the foreach loops.  The C# version of the query statement did not get translated correctly and returned a huge dataset.

I have a working E9 BPM that I am converting to E10.  I have the code converted and will compile, but there is a problem when I try to run the code in its entirety.  I receive a EntityException stating a New transaction is not allowed because there are other threads running in the session.  The code is intended to create a part along with all its associated tables like PartPlant, PartWhse, etc.  The code is very similar so I will only provide a small section.  I suspect it has to do with how ABL FOR EACH versus c# foreach work.


ABL:

            FOR EACH t-partplant WHERE t-partplant.company = t-part.company AND
                     t-partplant.partnum = t-part.partnum:
               FIND partplant WHERE partplant.company = t-part.company AND
                    partplant.partnum = part.partnum AND
                    partplant.plant = t-partplant.plant NO-LOCK NO-ERROR.
               IF NOT AVAIL partplant THEN DO:
                  CREATE partplant.
                  BUFFER-COPY t-partplant EXCEPT t-partplant.partnum TO partplant.
                  ASSIGN
                     partplant.partnum = part.partnum.
               END.
            END.


C#

foreach (var t_partplant_iterator in (from t_partplant_Row in Db.PartPlant
                                      where t_partplant_Row.Company == t_partplant_Row.Company &&
                                      t_partplant_Row.PartNum == t_partplant_Row.PartNum
                                      select t_partplant_Row))
{
    t_partplant = t_partplant_iterator;
    partplant = (from partplant_Row in Db.PartPlant
                 where partplant_Row.Company == t_part.Company &&
                 partplant_Row.PartNum == partplant_Row.PartNum &&
                 partplant_Row.Plant == t_partplant.Plant
                 select partplant_Row).FirstOrDefault();
    if (partplant == null)
    {
        partplant = new Erp.Tables.PartPlant();
        Db.PartPlant.Insert(partplant);
        BufferCopy.CopyExceptFor(t_partplant, partplant, Erp.Tables.PartPlant.ColumnNames.PartNum);
        partplant.PartNum = part.PartNum;
    }
}


If only run a single foreach section (i.e. only create the PartPlant table and nothing further), the code will finish but very, very slow.  If I add a couple more table's foreach sections, I will see the error.   I have the feeling the foreach loop is creating an inefficient query. 


Any ideas?

Tim 

In your FIND statement the second field joins after AND should “part.partnum” be “t-part.partnum”.

 

Sincerely,

 

Patrick Winter

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com]
Sent: Tuesday, May 10, 2016 15:41
To: vantage@yahoogroups.com
Subject: [Vantage] E9 to E10 BPM code conversion problem

 

 

I have a working E9 BPM that I am converting to E10.  I have the code converted and will compile, but there is a problem when I try to run the code in its entirety.  I receive a EntityException stating a New transaction is not allowed because there are other threads running in the session.  The code is intended to create a part along with all its associated tables like PartPlant, PartWhse, etc.  The code is very similar so I will only provide a small section.  I suspect it has to do with how ABL FOR EACH versus c# foreach work.

 

ABL:

            FOR EACH t-partplant WHERE t-partplant.company = t-part.company AND
                     t-partplant.partnum = t-part.partnum:
       &nbs p;       FIND partplant WHERE partplant.company = t-part.company AND
                    partplant.partnum = part.partnum AND
                    partplant.plant = t-partplant.plant NO-LOCK NO-ERROR.
               IF NOT AVAIL partplant THEN DO:
                  CREATE partplant.
                  BUFFER-COPY t-partplant EXCEPT t-partplant.partnum TO partplant.
                  ASSIGN
     &n bsp;               partplant.partnum = part.partnum.
               END.
            END.

 

C#

foreach (var t_partplant_iterator in (from t_partplant_Row in Db.PartPlant
                                      where t_partplant_Row.Company == t_partplant_Row.Company &&
                                      t_partplant_Row.PartNum == t_partplant_ Row.PartNum
                                      select t_partplant_Row))
{
    t_partplant = t_partplant_iterator;
    partplant = (from partplant_Row in Db.PartPlant
                 where partplant_Row.Company == t_part.Company &&
                 partplant_Row.PartNum == partplant_Row.PartNum &&
                 partplant_Row.Plant == t_partplant.Plant
                 select partplant_Row).FirstOrDefault() ;
    if (partplant == null)
    {
        partplant = new Erp.Tables.PartPlant();
        Db.PartPlant.Insert(partplant);
        BufferCopy.CopyExceptFor(t_partplant, partplant, Erp.Tables.PartPlant.ColumnNames.PartNum);
        partplant.PartNum = part.PartNum;
    }
}

 

If only run a single foreach section (i.e. only create the PartPlant table and nothing further), the code will finish but very, very slow.  If I add a couple more table's foreach sections, I will see the error.   I have the feeling the foreach loop is creating an inefficient query. 

 

Any ideas?

Tim 

This e-mail and any attachments may contain confidential and privileged information. If you are not the intended and/or named recipient or recipients, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient or recipients is unauthorized and may be illegal. Any views or opinions expressed in this email are those of the author and do not necessarily represent those of the Specialty Screw Corporation. Warning: Although precautions have been taken to make sure no viruses are present in this email, Specialty Screw Corporation cannot accept responsibility for any loss or damage that may arise from the use of this email or attachments.
This e-mail and any attachments may contain confidential and privileged information. If you are not the intended and/or named recipient or recipients, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient or recipients is unauthorized and may be illegal. Any views or opinions expressed in this email are those of the author and do not necessarily represent those of the Specialty Screw Corporation. Warning: Although precautions have been taken to make sure no viruses are present in this email, Specialty Screw Corporation cannot accept responsibility for any loss or damage that may arise from the use of this email or attachments.   ­­  
The ABL code is correct.  We are actually creating a second part "B" based off a part "A" so there is a mixing of both the t-part and part pieces.