--- tags: - data collection alias: tutorial-datacollection-edc-parameters-calculated-loadeddatabydefault timetoread: true description: "The documentation explains how data is optimized for expression evaluation, detailing excluded properties and loading methods" --- # Loaded Data by Default ## Optimization Due to performance concerns, by default the system does not include all the **Data Collection Instance** data when evaluating an expression. Below is a list of all the properties the system does not include for expression evaluation by default. ### Relations The data for the `DataCollectionParameters` property of a **Data Collection** object is taken from the relations collection of the **Data Collection**, specifically the relations with the key `DataCollectionParameter`. The exact same scenario happens for the `DataCollectionInstance` class, where the `DataCollectionPoints` property takes its data from the `DataCollectionPoint` relation. To avoid duplicating data, both relations are cleared from the JSON that will be used for expression evaluation. As the data was removed from the `RelationsCollection` altogether, you should refrain from attempting to query this property for the relevant information. Instead you should use the respective properties for **Data Collections** and **Data Collection Instances**. ### DataCollectionInstance * Area * Container * Facility * InspectionOrderStepSample * MaintenanceActivityOrder * ProcessResource * DataCollectionLimitSet * Flow * Step ### DataCollectionInstance.Product The **Product** of the **Data Collection Instance** is loaded if it exists, as well as the collection of Attributes of the **Product**. The system loads the **Product** with `levelsToLoad = 0` and discards several properties. Namely, the following properties, which are not available by default: * ApprovalRole * BOMFile * BOMFileImportTemplate * CADFile * CentroidFile * CentroidFileImportTemplate * DefaultMapDefinition * ProductGroup * Flow * Step ### DataCollectionInstance.Material If a **Material** context is provided, the **Material** is loaded with `levelsToLoad = 0`. The Attributes collection is also loaded, but only if the expression references it. The `TopMostMaterial` property is also optimized using the same criteria as the **Material** itself, and the `ParentMaterial` property is recursively optimized. The `LastProcessedResource` is optimized according to the criteria in the **DataCollectionInstance.Resource** section (see below). The following properties are not loaded by default: * CurrentBOMInstance * CurrentBOMVersion * CurrentChecklistInstance * CurrentDataCollectionInstance * CurrentDurablesBOMInstance * CurrentDurablesBOMVersion * CurrentInspectionOrder * CurrentInspectionOrderStepSample * CurrentMaterialTransfer * CurrentNote * CurrentRecipeInstance * CurrentSamplingPattern * CurrentSendAheadRun * LastProcessStepResource * LineFlowVersion * Manufacturer * MaterialTransferFromFacility * ProductionOrder * RequiredFutureAction * RequiredResource * Supplier * Facility * Flow * InTransitToFacility * LastProcessedResource * LastRecipe * MasterMap * ParentMaterial * Product * RequiredService * Step ### DataCollectionInstance.Resource If a **Resource** context is provided instead of a **Material** context, the exact same logic of the **Material** still applies. The following **Resource** properties are not loaded by default: * CurrentMainState * LastMaterial * LastProduct * LastProductGroup * LastProductionOrderStep * LastRecipe * LastService * LastStep * SelectedRecipe * Area * SortRuleSet ## How to Load Data Not Included by Default If you require any of the properties that are not loaded by default by the system, you can load them explicitly by using a DEE action. For this purpose, the function `DataCollectionInstance.ToJObjectForExpressionEvaluation(IDataCollectionInstance dci)` contains hooks so that a DEE can modify the provided `dci` parameter prior to the JSON serialization. This allows a DEE to load properties that were optimized out of the object. The action group for these DEEs is **BusinessObjects.DataCollectionInstance.ToJObjectForExpressionEvaluation**. The following objects are passed to the DEEs: * Pre * DataCollectionInstanceToEvaluate: the optimized **Data Collection Instance**, with all the aforementioned properties removed. * OriginalDataCollectionInstance: the original **Data Collection Instance** with no properties optimized. * Post * DataCollectionInstanceToEvaluate: the optimized **Data Collection Instance**, with all the aforementioned properties removed. * OriginalDataCollectionInstance: the original **Data Collection Instance** with no properties optimized. * JObjectResult: the JObject that resulted from this call method. The original **Data Collection Instance** object is provided because when a new **Data Collection Instance** is being created, it does not yet exist in the system, so the first level properties that were optimized cannot be loaded by using `dci.Load(0)`. A possible workaround is to assign the required properties from the original DCI to the optimized DCI, as follows: ```c# UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects.Abstractions"); UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects.Abstractions"); UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects"); UseReference("Cmf.Foundation.Common.dll", "Cmf.Foundation.Common"); UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects"); UseReference("Cmf.Navigo.Common.dll", "Cmf.Navigo.Common"); var serviceProvider = (IServiceProvider)Input["ServiceProvider"]; if (!Input.ContainsKey("DataCollectionInstanceToEvaluate")) { throw new ArgumentNullCmfException("DataCollectionInstanceToEvaluate"); } if (!Input.ContainsKey("OriginalDataCollectionInstance")) { throw new ArgumentNullCmfException("OriginalDataCollectionInstance"); } IDataCollectionInstance dciToEvaluate = (IDataCollectionInstance)Input["DataCollectionInstanceToEvaluate"]; IDataCollectionInstance dci = (IDataCollectionInstance)Input["OriginalDataCollectionInstance"]; dciToEvaluate.Area = dci.Area; dciToEvaluate.Flow = dci.Flow; Input["DataCollectionInstanceToEvaluate"] = dciToEvaluate; return Input; ``` If you require properties from the **Material**, **Resource** or **Product** that were optimized, you can use a similar code to this one: ```c# UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects.Abstractions"); UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects.Abstractions"); UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects"); UseReference("Cmf.Foundation.Common.dll", "Cmf.Foundation.Common"); UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects"); UseReference("Cmf.Navigo.Common.dll", "Cmf.Navigo.Common"); var serviceProvider = (IServiceProvider)Input["ServiceProvider"]; if (!Input.ContainsKey("DataCollectionInstanceToEvaluate")) { throw new ArgumentNullCmfException("DataCollectionInstanceToEvaluate"); } if (!Input.ContainsKey("OriginalDataCollectionInstance")) { throw new ArgumentNullCmfException("OriginalDataCollectionInstance"); } IDataCollectionInstance dciToEvaluate = (IDataCollectionInstance)Input["DataCollectionInstanceToEvaluate"]; IDataCollectionInstance dci = (IDataCollectionInstance)Input["OriginalDataCollectionInstance"]; dciToEvaluate.Area = dci.Area; if (dciToEvaluate.Material != null) { dciToEvaluate.Material.Load(0); dciToEvaluate.Material.Step.LoadStepAreas(); } if (dciToEvaluate.Resource != null) { dciToEvaluate.Resource.Load(0); } if (dciToEvaluate.DataCollection != null) { dciToEvaluate.DataCollection.Load(0); } Input["DataCollectionInstanceToEvaluate"] = dciToEvaluate; return Input; ```