访问联接的表数据

时间:2018-04-30 20:44:02

标签: acumatica

这是修改后的代码和我得到的错误。使用调试我已经确认它发生在:

var ret = cmd.Select();

protecting the users' data

这是完整的代码。

[PXFilterable]
public PXFilteredProcessing<EDASNShipProj, EDCreateASNFilter> Shipment;

protected virtual IEnumerable shipment()
{
    int ii = 0;
    foreach (var row in Shipment.Cache.Cached)
    {
        ii++;
        yield return row;
    }
    if (ii == 0)
    {            
    var cmd = new PXSelectJoin<SOShipment,
        LeftJoin<SOOrderShipment, On<SOShipment.shipmentNbr, Equal<SOOrderShipment.shipmentNbr>>,
        LeftJoin<SOOrder, On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>>,
        Where2<Where2<Where2<Where2<Where2<Where2<Where2<
                Where<Current<EDCreateASNFilter.customerID>, IsNull,
                    Or<SOOrderExt.usrEDICustomerId, Equal<Current<EDCreateASNFilter.customerID>>>>,
            And<Where<Current<EDCreateASNFilter.startDate>, IsNull,
                    Or<SOShipment.shipDate, GreaterEqual<Current<EDCreateASNFilter.startDate>>>>>>,
            And<Where<SOShipment.shipDate, LessEqual<Current<EDCreateASNFilter.endDate>>>>>,
            And<Where<Current<EDCreateASNFilter.shipVia>, IsNull,
                    Or<SOShipment.shipVia, Equal<Current<EDCreateASNFilter.shipVia>>>>>>,
            And<Where<Current<EDCreateASNFilter.truckNbr>, IsNull,
                    Or<SOShipmentExt.usrTruckNbr, Equal<Current<EDCreateASNFilter.truckNbr>>>>>>,
            And<Where<SOShipment.status, Equal<SOShipmentStatus.open>>>>,
            And<Where<SOShipmentExt.usrEDIStatus, Equal<SOShipmentEDIStatus.truckAssigned>,
                    Or<SOShipmentExt.usrEDIStatus, Equal<SOShipmentEDIStatus.newStat>>>>>,
            And<Where<SOOrder.customerRefNbr, IsNotNull>>>,
        OrderBy<Asc<SOShipment.customerID,
                Asc<SOOrderExt.usrEDICustomerId,
                Asc<SOOrderExt.usrEDICustomerVendorId,
                Asc<SOShipment.shipVia,
                Asc<SOShipmentExt.usrTruckNbr,
                Asc<SOShipment.customerLocationID>>>>>>>>(this);
    cmd.View.Clear();
    var ret = cmd.Select();
    if (ret != null)
    {
        EDASNShipProj shipProj = new EDASNShipProj();
        foreach (PXResult<SOShipment, SOOrderShipment, SOOrder> record in ret)
        {
            shipProj = new EDASNShipProj();
            SOShipment shipment = (SOShipment)record;
            SOShipmentExt soShipmentExt = shipment.GetExtension<SOShipmentExt>();
            SOOrder soOrder = (SOOrder)record;
            SOOrderExt soOrderExt = soOrder.GetExtension<SOOrderExt>();
            shipProj.OrderNbr = soOrder.OrderNbr;
            shipProj.CustomerRefNbr = soOrder.CustomerRefNbr;
            shipProj.CustomerOrderNbr = soOrder.CustomerOrderNbr;
            shipProj.UsrTruckNbr = soShipmentExt.UsrTruckNbr;
            shipProj.UsrEDICustomerId = soOrderExt.UsrEDICustomerId;
            shipProj.UsrEDICustomerVendorId = soOrderExt.UsrEDICustomerVendorId;
            shipProj.UsrEDIStatus = soShipmentExt.UsrEDIStatus;
            shipProj.CustomerID = shipment.CustomerID;
            shipProj.CustomerLocationID = shipment.CustomerLocationID;
            shipProj.ShipVia = shipment.ShipVia;
            shipProj.ShipmentNbr = shipment.ShipmentNbr;
            shipProj.ShipDate = shipment.ShipDate;
            shipProj = Shipment.Insert(shipProj);
            Shipment.Cache.SetStatus(shipProj, PXEntryStatus.Held);
            yield return shipProj;
        }
    }
    Shipment.Cache.IsDirty = false;

2 个答案:

答案 0 :(得分:2)

想法是Select()返回主DAC的PXResultset。然后,您可以遍历此并转换为已连接的DAC。

以下是一个例子:

// The static Select() method is called to execute a BQL command.
PXResultset<OrderDetail> result =
    PXSelectJoin<OrderDetail, InnerJoin<SalesOrder,
        On<SalesOrder.orderNbr, Equal<OrderDetail.orderNbr>>>>.Select(this);

// Iterating over the result set:
// PXResult should be specialized with the DACs of all joined tables
// to be able to cast to these DACs.
foreach(PXResult<OrderDetail, SalesOrder> record in result)
{
    // Casting a result set record to the OrderDetail DAC:
    OrderDetail detail = (OrderDetail)record;
    // Casting a result set record to the SalesOrder DAC:
    SalesOrder order = (SalesOrder)record;
    ...
}

请查看此文章以获取更多信息

https://help.acumatica.com/(W(8))/Wiki/ShowWiki.aspx?pageid=8609c829-7b9c-4660-acf9-891b0971b6a3

答案 1 :(得分:0)

查看使用var时推断的类型: enter image description here

'a'的类型为'PXResultset&lt; ARSalesPerTran&gt; '在这个例子中

如果我要将它分配给另一个不同类型的变量'b',如'PXResultset&lt; ARSalesPerTran,ARSalesPerTranExt,ARRegister&gt; '编译器将报告它不能隐式转换'PXResultset&lt; ARSalesPerTran&gt; '到'PXResult&lt; ARSalesPerTran,ARSalesPerTranExt,ARRegister&gt; ”。

PXResult<ARSalesPerTran, ARSalesPerTranExt, ARRegister> b = a;

enter image description here

然而,编译器将允许显式转换:

PXResult<ARSalesPerTran, ARSalesPerTranExt, ARRegister> b = (PXResult< ARSalesPerTran, ARSalesPerTranExt, ARRegister>)a;

简而言之,这与C#推断类型系统(var)的工件有关,而不是Acumatica功能。