Acumatica 22 R1:字段更新事件中无需额外查询访问关联表?
在Acumatica 22 R1中无需额外查询访问关联表记录
可以实现,有两种常用方法避免额外查询开销:
方法1:利用已加载的PXSelectJoin视图获取关联记录
因为你已经定义了包含InnerJoin的MyView,当触发字段更新事件的Detail行属于该视图时,可通过视图的Current属性结合PXResult提取关联的Header记录——视图已预先加载关联数据,无需发起新查询:
public void _(Events.FieldUpdated<Detail.someField> e) { Detail dtl = e.Row as Detail; if (dtl == null) return; // 从视图当前记录中获取包含Header的结果集 PXResult<Detail, Header> viewResult = MyView.Current as PXResult<Detail, Header>; if (viewResult != null) { Header hdr = viewResult.GetItem<Header>(); if (hdr != null) { // 此处直接使用关联的Header记录 // 示例:访问Header字段 string headerName = hdr.Name; } } }
方法2:通过DAC父级关联配置获取父记录
如果在Detail DAC的hdrId字段上配置PXParent属性,可直接通过缓存的GetParent方法获取关联的Header记录,无需额外查询:
第一步:在Detail DAC中配置父级关联
public class Detail : IBqlTable { // 其他字段... [PXDBInt(IsKey = true)] [PXParent(typeof(Select<Header, Where<Header.id, Equal<Current<Detail.hdrId>>>>))] [PXUIField(DisplayName = "Header ID")] public virtual int? HdrId { get; set; } public abstract class hdrId : PX.Data.BQL.BqlInt.Field<hdrId> { } // 其他字段... }
第二步:在FieldUpdated事件中获取父记录
public void _(Events.FieldUpdated<Detail.someField> e) { Detail dtl = e.Row as Detail; if (dtl == null) return; // 直接从缓存获取关联的Header父记录 Header hdr = e.Cache.GetParent(dtl) as Header; if (hdr != null) { // 此处使用Header记录 } }
注意:方法1仅当触发事件的Detail行是从MyView中加载时有效;方法2依赖DAC的父级关联配置,适用于存在明确父子关系的场景。
内容的提问来源于stack exchange,提问作者MikeNIke
相关产品推荐
相关产品推荐

