Material Queue warehouse and bin with max onhandqty update

,

Hi all,
I’m working with a company that does not have primary bins defined. I’m attempting to update the material queue with a bin with the most quantity for the part. I can do this in SQL or BAQ but am fuzzy on how I can do this in a BPM using C#.
Here’s what I have so far, any help would be much appreciated.

Erp.Tables.PartBin PartBin;
Erp.Tables.PartPlant PartPlant;

    foreach (var ttMtlQueue_iterator in (from ttMtlQueue_Row in ttMtlQueue
    where string.Equals(ttMtlQueue_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase) || string.Equals(ttMtlQueue_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase)
    select ttMtlQueue_Row))
    
    
{
    //Runs to update PartBin
    var ttMtlQueueRow = ttMtlQueue_iterator;
   
    
    PartBin = (from PartBin_Row in Db.PartBin
    where PartBin_Row.Company == ttMtlQueueRow.Company &&
    PartBin_Row.PartNum == ttMtlQueueRow.PartNum 
    select PartBin_Row).FirstOrDefault();

      if (PartBin != null)
      {
    
      PartBin.WarehouseCode = ttMtlQueueRow.FromWhse;
      PartBin.BinNum = ttMtlQueueRow.FromBinNum;
  
      }

}