EntityDAC

TCustomEntityContext.GetEntity<T> Method

The method is designed for retrieving an existing entity instance by specified criteria.

Class

TCustomEntityContext

Syntax

function GetEntity<T: TMappedEntity>(const KeyValue: Variant): T; overload;

Type parameters
T
The class type of the entity to be retrieved
Parameters
KeyValue
The value of the entity primary key.

Remarks

The method returns an entity instance of the specified class type selected by the specified primary key value. The entity instance created by this method is initially attached to the data context and placed to the object cache (in contrast to the TCustomEntityContext.CreateEntity method), therefore you can already perform modification operations for the instance: TCustomEntityContext.Delete, TCustomEntityContext.Cancel) without pre-calling TCustomEntityContext.Attach. In addition, this entity instance will be automatically destroyed, and there will be no need to provide for its manual destruction.

Example

Examples of calling the method:

var
  EmpEntity: TEmp;
begin
EmpEntity := Context.GetEntity<TEmp>(EmpType, 1);
  // ...
end; 

See Also

© 1997-2017 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback