如何使用BQL生成具有特定表列的SQL

时间:2017-07-21 17:10:41

标签: acumatica

当我用BQL语法加入两个DAC时,它会生成SQL,从而选择两个表中的所有列。如果我想选择一个表格的列以达到良好的执行计划怎么办?

1 个答案:

答案 0 :(得分:0)

您可以尝试查看PXProjection,其中列被定义为投影类中的字段。 PXProjection就像在Acumatica中作为DAC的SQL视图。只需搜索PXProjection的Acumatica来源,您就会找到许多示例。请注意,在课程中,您需要为每个"列设置BqlField"因此,进程知道您的投影字段映射到哪个table.field。

快速加入PXProjection如下。在此示例中,DAC中只有1列,它映射到APRegister.docType

[PXProjection(typeof(Select2<APRegister, 
        InnerJoin<APInvoice, On<APInvoice.docType, Equal<APRegister.docType>, 
            And<APInvoice.refNbr, Equal<APRegister.refNbr>>>, 
        InnerJoin<APPayment, On<APPayment.docType, Equal<APRegister.docType>, 
            And<APPayment.refNbr, Equal<APRegister.refNbr>>>>>, 
        Where<APRegister.docType, Equal<APDocType.quickCheck>, 
            Or<APRegister.docType, Equal<APDocType.voidQuickCheck>>>>), Persistent = true)]
[Serializable]
public partial class APQuickCheck : APRegister
{
    #region DocType
    public new abstract class docType : PX.Data.IBqlField
    {
    }
    [PXDBString(3, IsKey = true, IsFixed = true, BqlField = typeof(APRegister.docType))]
    [PXDefault(APDocType.QuickCheck)]
    [APQuickCheckType.List()]
    [PXUIField(DisplayName = "Type", Visibility = PXUIVisibility.SelectorVisible, Enabled = false)]
    [PXFieldDescription]
    public override String DocType
    {
        get
        {
            return this._DocType;
        }
        set
        {
            this._DocType = value;
        }
    }
    #endregion
}