Lightweight Persist To Database


Hello everybody,

today I want to describe following use case. Quite often it is needed to persist to database one or another DAC class, which is filled by some data. 

As usually I see people do this via hard coding of DAC class inside of the Graph. But today I want to share with you a way of persisting DAC class without hardcoding it as a view. 

In order to accomplish this, you can use following graph:

public class ImportEntitiesInsertion : PXGraph<ImportEntitiesInsertion>
    public string AddView(Type dacType)
        var viewName = "_DYNAMIC_" + dacType.GetLongName();
        if (!this.Views.ContainsKey(viewName))
            var command = BqlCommand.CreateInstance(typeof(Select<>), dacType);
            var newView = new PXView(thistrue, command);
            Views.Add(viewName, newView);
        return viewName;


After that, in some other place of the code, you can use this graph like this:


var graphForInsertion = PXGraph.CreateInstance<ImportEntitiesInsertion>();
var dacType = typeof(SOOrder); 
var viewName = graphForInsertion.AddView(dacType);
for (int i = 0; i < 10; i++)
    var newOrd = new SOOrder();


 What I especially like about this approach, is that records will be persisted initially in the cache, and only after you'll call Persist, all bunch of records will be persisted to database.



Order Of Views In Graph In Acumatica


Hello everybody,

note of today is value of orders. In the word of C# if you work with your class, you as usually don't care what you declare in your code. But in Acumatica graph order of data viewes is important, because they define order of saving data to the database. If you think that surprises are completed then here it is another one: order of viewes doesn't define order of data viewes execution. And the third one, view that is binded to PrimaryView should be defined first in the graph. 

No Comments


Add a Comment