[ROOT] / doc / toc / ARCQuery / Class / EntityMethodKey

AllEntityMethodKeysForEntityTypeDict , AllEntityMethodKeysForEntityTypeList , FunctionKeys , Method , MethodNameAsIK , QuantileKey , ReturnType , ToString , TryGetForeignField , TryGetP , TryGetPInternal


Key able to call read-only methods defined in the entity class with names like 'TryGet{FieldName}'.

Some common usages of this would be to implement:
- In a class called 'Customer' with 'FirstName' and 'LastName', a new property 'Name'.
- In a class called 'OrderLine' with 'Quantity' and 'UnitPrice', a new property 'Sum'.

In essence this is making an entity class able to describe itself, something which is quite natural in many cases.

The principle can also be used to simplify querying while still having tables normalized.
If for instance address data for 'Customer' objects is normalized into a separate table 'Geography' then one could implement properties on 'Customer' like 'City', 'State', 'Country'.
This would enable querying for 'Customer' like
'SELECT Name, Address, City, State, Country'
instead of the more laborous
'SELECT Geography.Name, Geography.Address, Geography.City, Geography.State, Geography.Country'
(see TryGetForeignField which is a helper method for this purpose).

Implementations of a few such properties can often significantly reduce the complexity of queries / reduce the need for denormalizing tables in the database.

The risk of bugs are also reduced since the properties will only be defined in one place, as close as possible to its source propertiesinstead of complex query components being repeated multiple times in a reporting system for instance.

In addition, memory and disk space is conserved because the returned values are usually ephemeral.
Performance MAY also be increased as the values are only calculated when needed.

This class (EntityMethodKey) looks for such entity property defining methods through reflection.
It is able to call methods with signatures like either:
bool TryGet{KeyName}(out IP retval, out string errorResponse) (see Simple)
or
bool TryGet{KeyName}(IP dataStorage, IK thisKey, out IP retval, out string errorResponse) (see Complex)

The second overload makes the entity class able to query other parts of the system in order to calculate the return value.

These should be read-only methods / read-only properties, that is, they should not change the state of the entity or the data storage.

Note: 'out IP retval' can be any type assignable to IP, so it is recommended to use more strongly typing in the method signature, like 'out PValue<DateTime> retval' for instance.

See also NewKey (creating new keys (new fields) for all entity object types).


AllEntityMethodKeysForEntityTypeDictReturns all EntityMethodKey in the class definition of the given entity type.
AllEntityMethodKeysForEntityTypeListReturns List sorted by Method Name of Value of Dictionary returned by AllEntityMethodKeysForEntityTypeDict
FunctionKeysAll FunctionKeys chained at end of compound key (but before an eventual QuantileKey).
MethodThe actuall TryGet method implemented in the relevant entity class.
MethodNameAsIKName of TryGet method but without 'TryGet' in name
QuantileKeyEventual final QuantileKey at end of compound key.
ReturnTypeThe type of the 'retval' out-parameter of the method.
ToStringThe ToString representation is the one relevant when used as key, like in IK or when selecting like 'SELECT {fieldName}'.
TryGetForeignFieldReturns foreign field through foreign key given.
TryGetPThe outwards facing executor, understanding use of FunctionKeys.
TryGetPInternalThe internal executor, containing the specific functionality for how to evaluate the key.

Details

Generated 2022-06-28 06:01:58.245 UTC