Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 2.37 KB

File metadata and controls

52 lines (42 loc) · 2.37 KB

PX1072

This document describes the PX1072 diagnostic.

Summary

Code Short Description Type Code Fix
PX1072 BQL queries must be executed within the context of an existing PXGraph instance. Warning (Level 1: Significant) Available

Diagnostic Description

A new PXGraph instance should not be used in the execution of BQL queries. Instead, an existing PXGraph instance should be used. Because the creation of a PXGraph instance is an expensive operation, the instantiation of unnecessary graph instances slows the performance of the application. Also, when you create a new graph, you miss the query results that have already been cached in an existing graph.

The code fix replaces new PXGraph() or PXGraph.CreateInstance<T>() in the BQL query with the existing PXGraph instance of your choice.

Example of Code That Results in the Warning

public class ARInvoiceEntry : PXGraph<ARInvoiceEntry, ARInvoice>
{
	public ARInvoice GetInvoice(PXGraph graph, string refNbr)
	{
		var invoiceEntry = PXGraph.CreateInstance<ARInvoiceEntry>();

		var invoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>
			.Select(new PXGraph(), refNbr); //The PX1072 warning is displayed for this line.
	}
}

Example of Code Fix

public class ARInvoiceEntry : PXGraph<ARInvoiceEntry, ARInvoice>
{
	public ARInvoice GetInvoice(PXGraph graph, string refNbr)
	{
		var invoiceEntry = PXGraph.CreateInstance<ARInvoiceEntry>();

        //First variant of fix
		var invoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>
			.Select(this, refNbr); //`new PXGraph()` is replaced with the `this` instance.
        /*
        // Second variant of fix
        var invoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>
			.Select(graph, refNbr); //`new PXGraph()` is replaced with the `graph` instance. 
        // Third variant of fix
        var invoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>
			.Select(invoiceEntry, refNbr); //`new PXGraph()` is replaced with the `invoiceEntry` instance. 
        */
	}
}