-->

Create DAC that inherits from other DAC

2019-07-27 00:33发布

问题:

In Acumatica, there are instances where a DAC for a screen (e.g., Projects) is not directly bound to a table (PMProject), but inherits a DAC that IS bound to a table (Contract). Is there a good instructional reference source for doing this?

回答1:

This theme is partially covered in T200 training course(Example 9.1).

Basic principles:

If you inherited some class DAC2 from the DAC1 bound to the SQL table then DAC2 will also be bound to the same SQL table.

[Serializable]
public partial class DAC1 : IBQLTable
{
    public abstract class tableID : PX.Data.IBqlField
    {
    }
    [PXDBIdentity()]
    public virtual Int32? TableID { get; set;}
}
[Serializable]
public partial class DAC2 : DAC1
{}

However, fields from DAC1 will be used in the generated SQL query.

PXSelect<DAC2, Where<DAC2.tableID, Equal<Required<DAC2.tableID>>>(...) ->
SELECT [DAC2].[TableID] FROM DAC1 DAC2 Where [DAC1].[TableID] = @P0

To allow BQL generate SQL queries with DAC2 field you should replace abstract class of this field in DAC2

[Serializable]
public partial class DAC2 : DAC1
{
    public new abstract class tableID : PX.Data.IBqlField
    {
    }
}

SQL query will look like that:

SELECT [DAC2].[TableID] FROM DAC1 DAC2 Where [DAC2].[TableID] = @P0

To override attributes of the field you should override corresponding property in DAC2

[Serializable]
public partial class DAC2 : DAC1
{
    public new abstract class tableID : PX.Data.IBqlField
    {
    }
    [PXDBIdentity()]
    [PXUIField(DisplayName = "ID")]
    public override Int32? TableID {get; set;}
}

If you want DAC2 to be different from DAC1, for instance you want to add some fields to DAC2 but you also want to keep DAC1 unmodified then you can use PXTable attribute(e.g. ARInvoice class)

[PXTable]
[Serializable]
public partial class DAC2 : DAC1
{
    public new abstract class tableID : PX.Data.IBqlField
    {
    }
    [PXDBIdentity()]
    [PXUIField(DisplayName = "ID")]
    public override Int32? TableID {get; set;}

    public abstract class description : PX.Data.IBqlField
    {
    }
    [PXDBString(60)]
    public virtual String Description{get; set;}
}

The SQL query will look like that:

SELECT [DAC2].[TableID], [DAC2.Description] 
FROM (SELECT [DAC1].[TableID] as TableID, [DAC2].[Description] as Description 
    FROM DAC1 Inner Join DAC2 on DAC1.TableID=DAC2.TableID) DAC2 
Where [DAC2].[TableID] = @P0


标签: acumatica