PXSelector and DirtyRead

Hi Everyone,

Want to speak today about Dirty Read property of selector.
Base explanation you can find in Acumatica API reference. How ever this one is very basic, so let me try to share with you real case.

You may know about Readonly vs Merged data retrial from DataView. Basically if you use PXSelectReadonly data-view it will always return data only stored in database. If you use standard data-view like PXSelect Acumatica will get data from DB and than merge it with unsaved data from cache.
This is fully applicable for data-views (PXSelect, PXSelectReadonly) and selectors as well. When you define PXSelectorAttribute than it will be always read-only by default. However you can make it not read-only using DirtyRead = true parameter.

[PXSelector(typeof(Users.pKID), SubstituteKey = typeof(Users.username), DirtyRead = true)]
protected virtual void Contact_UserID_CacheAttached(PXCache cache) { ... }

Why you may need it? Lets imagine you have 2 DACs that are refers each other thought text key with PXSelectorAttribute.

In this case if you insert new record for DAC 1 and DAC 2 simultaneously you will may have a problem with selector as record of DAC 1 is not yet saved and selector will throw Item not Found exception.
Here exactly DirtyRead comes to help us – in this scenrarion selector with DirtyRead=true will select DAC1 from database, merge it with cache (new inserted record) and no error will be triggered.

In the example of PXSelector above Acumatica allows to link Contact with just created use account. So that means that if you create user on the fly with code and it is not saved but needs to be linked with contact – DirtyRead helps us.

Profit! Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *