Part Alloc Exception

From what I understand, PartAlloc is an in-memory table so I’m getting the exception below. Does anyone know how I can correctly do this? I want to enumerate though the rows I’m selecting later.

var OrderRelRows = (from OrderRel_Row in Db.PartAlloc
where OrderRel_Row.Company == Company && OrderRel_Row.PartNum == 
tt.PartNum && OrderRel_Row.WarehouseCode == WarehouseCode
&& OrderRel_Row.BinNum == tt.FromBinNum                   
select new {OrderRel_Row.OrderNum, OrderRel_Row.OrderLine,OrderRel_Row.OrderRelNum, OrderRel_Row.AllocatedQty}).ToList();

image

I think you are missing the “tt” in front of the Warehouse code in your query as well as in front of Company:

var OrderRelRows = (from OrderRel_Row in Db.PartAlloc
where OrderRel_Row.Company == CompanyID && OrderRel_Row.PartNum == 
tt.PartNum && OrderRel_Row.WarehouseCode == tt.WarehouseCode
&& OrderRel_Row.BinNum == tt.FromBinNum                   
select new {OrderRel_Row.OrderNum, OrderRel_Row.OrderLine,OrderRel_Row.OrderRelNum, OrderRel_Row.AllocatedQty}).ToList();

Alternatively, you could write it like this:

var OrderRelRows = Db.PartAlloc.Where(PA => PA.Company == CompanyID && PA.PartNum == tt.PartNum && PA.WarehouseCode == tt.WarehouseCode && PA.BinNum == tt.FromBinNum).Select(PA => new {PA.OrderNum,PA.OrderLine,PA.OrderRelNum,PA.AllocatedQty}).ToList();
2 Likes

@Jason_Woods still getting this exception

image

Could you post your full code?

Jason Woods
http://LinkedIn.com/in/jasoncwoods

using (var txScope1 = IceContext.CreateDefaultTransactionScope())
{ 
bool out3 = false;
bool out4 = false;
bool out5 = false;
bool out98 = false;
string out6 = "";
string out7 = "";
string out8 = "";
string bin = "";
string out2 ="";
bool out9 = false;
int OrderNum=0;
int OrderLine=0;
int OrderRelNum=0;

var tt = ttInvTrans[0];
{
 
var OrderRelRows = Db.PartAlloc.Where(PA => PA.Company == tt.Company && PA.PartNum == tt.PartNum && PA.WarehouseCode == tt.FromWarehouseCode && PA.BinNum == tt.FromBinNum)
.Select(PA =>new {PA.OrderNum,PA.OrderLine,PA.OrderRelNum,PA.AllocatedQty}).ToList();                                    
                                     
using(var alloc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.OrderAllocSvcContract>(Db))
{
string PartNum = tt.PartNum;
bool out1=false;


foreach(var OrderRelRow in OrderRelRows)
{
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
var OrderAllocDataSet = new Erp.Tablesets.OrderAllocTableset();
var OrderAllocListDataSet = new Erp.Tablesets.OrderAllocListTableset();

OrderNum=OrderRelRow.OrderNum;
OrderLine=OrderRelRow.OrderLine;
OrderRelNum=OrderRelRow.OrderRelNum;
                                        
OrderAllocListDataSet = alloc.GetListFWB("OrderNum='"+OrderNum.ToString()+"' AND OrderLine="+OrderLine.ToString()+" AND OrderRelNum="+OrderRelNum.ToString(),0,1,out out1);
OrderAllocDataSet = alloc.OrderAllocationGetRows(OrderAllocListDataSet,1);



foreach (var drOA in OrderAllocDataSet.OrderAlloc)
{
//if (oa.AllocatedQty > 0)


//OrderAllocDataSet1.OrderAlloc.NewRow() = OrderAllocDataSet.OrderAlloc[i];
//OrderAllocDataSet1.OrderAlloc.Add();
drOA.SelectedForAction = true;
drOA.RowMod = "U";

}



foreach (var sup in OrderAllocDataSet.OrderAllocSupply)
{
sup.RowMod = "U";
}
var cd = Db.CrossDock.Where(x=>x.OrderNum == OrderRelRow.OrderNum && x.OrderLine == OrderRelRow.OrderLine && x.OrderRelNum == OrderRelRow.OrderRelNum).Select(x=>OrderRelRow).FirstOrDefault();
/*if (cd != null && OrderRelRow.AllocatedQty > 0 )
{
var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
foreach (var qt in q)
{
// will be ud field
qt.ServRef1 = "2";
}
}
else
{
var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
foreach (var qt in q)
{
//will be ud field
qt.ServRef1 = "1";
}
}*/
alloc.UnallocateAndUnreserve(ref OrderAllocDataSet, out out2);
alloc.RefreshSelectedRows(ref OrderAllocDataSet);
txScope.Complete();
}
}
}
}
txScope1.Complete();
}

I know I have some sloppy code in here that I’ll have to fix as well but I can’t seem to get rid of that error

Why do you have two transaction scopes? I would remove the middle one.

Not sure the reason (this was done awhile ago). Removed it and still am getting the same error.

Its not much different, but try this:

using (var txScope1 = IceContext.CreateDefaultTransactionScope())
{ 
  bool out3 = false;
  bool out4 = false;
  bool out5 = false;
  bool out98 = false;
  string out6 = "";
  string out7 = "";
  string out8 = "";
  string bin = "";
  string out2 ="";
  bool out9 = false;
  int OrderNum=0;
  int OrderLine=0;
  int OrderRelNum=0;

  foreach (var tt in ttInvTrans.Where(tt => !tt.Unchanged()));
  {
    var OrderRelRows = Db.PartAlloc.Where(PA => PA.Company == CompanyID && PA.PartNum == tt.PartNum && PA.WarehouseCode == tt.FromWarehouseCode && PA.BinNum == tt.FromBinNum).Select(PA => new {PA.OrderNum,PA.OrderLine,PA.OrderRelNum,PA.AllocatedQty}).ToList();                                    
    
    using(var alloc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.OrderAllocSvcContract>(Db))
    {
      string PartNum = tt.PartNum;
      bool out1=false;

      foreach(var OrderRelRow in OrderRelRows)
      {
        var OrderAllocDataSet = new Erp.Tablesets.OrderAllocTableset();
        var OrderAllocListDataSet = new Erp.Tablesets.OrderAllocListTableset();

        OrderNum=OrderRelRow.OrderNum;
        OrderLine=OrderRelRow.OrderLine;
        OrderRelNum=OrderRelRow.OrderRelNum;
                                                
        OrderAllocListDataSet = alloc.GetListFWB("OrderNum='"+OrderNum.ToString()+"' AND OrderLine="+OrderLine.ToString()+" AND OrderRelNum="+OrderRelNum.ToString(),0,1,out out1);
        OrderAllocDataSet = alloc.OrderAllocationGetRows(OrderAllocListDataSet,1);

        foreach (var drOA in OrderAllocDataSet.OrderAlloc)
        {
          //if (oa.AllocatedQty > 0)
            
          //OrderAllocDataSet1.OrderAlloc.NewRow() = OrderAllocDataSet.OrderAlloc[i];
          //OrderAllocDataSet1.OrderAlloc.Add();
          drOA.SelectedForAction = true;
          drOA.RowMod = "U";

        }

        foreach (var sup in OrderAllocDataSet.OrderAllocSupply)
        {
          sup.RowMod = "U";
        }
        var cd = Db.CrossDock.Where(x=>x.OrderNum == OrderNum && x.OrderLine == OrderLine && x.OrderRelNum == OrderRelNum).Select(x=>OrderRelRow).FirstOrDefault();
        /*if (cd != null && OrderRelRow.AllocatedQty > 0 )
        {
          var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
          foreach (var qt in q)
          {
            // will be ud field
            qt.ServRef1 = "2";
          }
        }
        else
        {
          var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
          foreach (var qt in q)
          {
            //will be ud field
            qt.ServRef1 = "1";
          }
        }*/
        alloc.UnallocateAndUnreserve(ref OrderAllocDataSet, out out2);
        alloc.RefreshSelectedRows(ref OrderAllocDataSet);
      }
    }
  }
  txScope1.Complete();
}

I’m getting the same error using your changes

I loaded this into Epicor. It validated:

using (var txScope1 = IceContext.CreateDefaultTransactionScope())
{ 
    bool out3 = false;
    bool out4 = false;
    bool out5 = false;
    bool out98 = false;
    string out6 = "";
    string out7 = "";
    string out8 = "";
    string bin = "";
    string out2 ="";
    bool out9 = false;
    int OrderNum=0;
    int OrderLine=0;
    int OrderRelNum=0;

    foreach (var tt in ttInvTrans.Where(tt => !tt.Unchanged()))
    {
        using(var alloc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.OrderAllocSvcContract>(Db))
        {
            string PartNum = tt.PartNum;
            foreach (var OrderRelRow in Db.PartAlloc.Where(PA => PA.Company == CompanyID && PA.PartNum == tt.PartNum && PA.WarehouseCode == tt.FromWarehouseCode && PA.BinNum == tt.FromBinNum).Select(PA => new {PA.OrderNum,PA.OrderLine,PA.OrderRelNum,PA.AllocatedQty}).ToList())
            {
                bool out1=false;
                var OrderAllocDataSet = new Erp.Tablesets.OrderAllocTableset();
                var OrderAllocListDataSet = new Erp.Tablesets.OrderAllocListTableset();
                
                OrderNum=OrderRelRow.OrderNum;
                OrderLine=OrderRelRow.OrderLine;
                OrderRelNum=OrderRelRow.OrderRelNum;
                                                        
                OrderAllocListDataSet = alloc.GetListFWB("OrderNum='"+OrderNum.ToString()+"' AND OrderLine="+OrderLine.ToString()+" AND OrderRelNum="+OrderRelNum.ToString(),0,1,out out1);
                OrderAllocDataSet = alloc.OrderAllocationGetRows(OrderAllocListDataSet,1);
                
                foreach (var drOA in OrderAllocDataSet.OrderAlloc)
                {
                  //if (oa.AllocatedQty > 0)
                    
                  //OrderAllocDataSet1.OrderAlloc.NewRow() = OrderAllocDataSet.OrderAlloc[i];
                  //OrderAllocDataSet1.OrderAlloc.Add();
                  drOA.SelectedForAction = true;
                  drOA.RowMod = "U";
                
                }
                
                foreach (var sup in OrderAllocDataSet.OrderAllocSupply)
                {
                  sup.RowMod = "U";
                }
                var cd = Db.CrossDock.Where(x=>x.OrderNum == OrderNum && x.OrderLine == OrderLine && x.OrderRelNum == OrderRelNum).Select(x=>OrderRelRow).FirstOrDefault();
                /*if (cd != null && OrderRelRow.AllocatedQty > 0 )
                {
                  var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
                  foreach (var qt in q)
                  {
                    // will be ud field
                    qt.ServRef1 = "2";
                  }
                }
                else
                {
                  var q =(from rel in Db.OrderRel where (rel.OrderNum == OrderRelRow.OrderNum && rel.OrderLine == OrderRelRow.OrderLine && rel.OrderRelNum == OrderRelRow.OrderRelNum) select rel);
                  foreach (var qt in q)
                  {
                    //will be ud field
                    qt.ServRef1 = "1";
                  }
                }*/
                alloc.UnallocateAndUnreserve(ref OrderAllocDataSet, out out2);
                alloc.RefreshSelectedRows(ref OrderAllocDataSet);
            }
        }
    }
    txScope1.Complete();
}

Yeah, it would validate but going to run it generated an exception. It turned out to this line was referencing OrderRelRow instead of x.OrderNum

var cd = Db.CrossDock.Where(x=>x.OrderNum == OrderRelRow.OrderNum && x.OrderLine == OrderRelRow.OrderLine && x.OrderRelNum == OrderRelRow.OrderRelNum).Select(x=>OrderRelRow).FirstOrDefault();