Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The class Consultingwerk.Windows.TempTableObjectMapping.TempTableFromTypeFactory allows developers to create a dynamic temp-table that matches the properties of a .NET type.

...

Code Block
titleSample code that builds an ABL temp-table from a .NET type
DEFINE VARIABLE cMapping AS CHARACTER NO-UNDO INIT "CustNum|CustomerNumber,Name,City|City(CLOB),Image,ModificationDate|ModDate(DATE),Balance,Weekday,Weekday|Wochentag(CHARACTER)" .
 
/* Get a reference to the .NET Type to map */
oType = Progress.Util.TypeHelper:GetType ("Consultingwerk.DotNetClassLibrary.SampleViewModel", TRUE) .
 
oFactory = NEW TempTableFromTypeFactory () .  
 
hTable = oFactory:CreateTempTable (oType,    /* Reference to the .NET Type */
                                   cMapping, /* Property/Field Mapping definition */
                                   "CustNum" /* Primary unique key fields for the temp-table */) .

Populating an instance of the .NET Value Object with data from the temp-table

The class Consultingwerk.Windows.TempTableObjectMapping.TempTableToObjectMapper allows developers to copy data from a temp-table buffer to an object instance and vice-versa.

The class methods CopyFromBuffer and CopyFromObject assume that both the object instance and a record in the provided temp-table buffer are already available (no factory functionality). The code expects the same property/field mapping to be provided as the TempTableFromTypeFactory class method CreateTempTable.

Code Block
titleSample code for populating a .NET value object from a temp-table record
oMapper = NEW TempTableToObjectMapper () .
 
oObject = NEW Consultingwerk.DotNetClassLibrary.SampleViewModel () . 


hBuffer = hTable:DEFAULT-BUFFER-HANDLE .


oMapper:CopyFromBuffer (hBuffer,   /* Source ABL buffer */
                        oObject    /* Target .NET object reference */,
                        cMapping)  /* Property/Field mapping definition */.

Populating a temp-table record with data from a .NET Value Object instance

The method CopyFromObject of the TempTableToObjectMapper class allows developers to assign field values in a record buffer with data from a .NET value object:

Code Block
titleSample to assign temp-table field values from a .NET value object
oMapper:CopyFromObject (oObject,   /* Source .NET object reference */
                        hBuffer,   /* Target ABL buffer */
                        cMapping,  /* Property/Field mapping definition */
                        ?, ?) .

The method supports turning Enumeration values either in their integer value of Character label.

The method CopyFromObject map also manipulate the before image information of a ProDataset member buffer. In this case it is expected that the .NET object provides a ReadOnlyDictionary of the original (unchanged) values, with the Property Name as the key and the original value as the value.

Code Block
titleSample to assign temp-table with before image information from .NET value object
oMapper:CopyFromObject (oObject,         /* Source .NET object reference */
                        hBuffer,         /* Target ABL buffer */
                        cMapping,        /* Property/Field mapping definition */
                        oObject:Changes  /* Reference to the Dictionary of before values */, 
                        FALSE)           /* FALSE: Modified row, TRUE: New row */	.

The method will manipulate the temp-table after buffer and before-buffer accordingly.