EntityDAC

TCustomEntityContext.CreateAttachedEntity Method

The method is designed for creating a new entity instance and simultaneous attaching it to the data context

Class

TCustomEntityContext

Syntax

function CreateAttachedEntity(MetaExpr: IMetaType; const KeyValues: array of Variant): TMappedEntity; overload;

Parameters
MetaExpr
The meta-type of the entity to be created.
KeyValues
The array of initial values of meta attributes forming the entity primary key.

Remarks

The method creates a new entity instance of the specified meta-type. The attributes forming the entity primary key will be initialized by the specified values. 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, M:Devart.EntityDAC.TEntityContext.Save(Devart.EntityDAC.TMappedEntity,System.Boolean), TCustomEntityContext.Cancel, without pre-calling TCustomEntityContext.Attach.

Example

var
  EmpType: IMetaType;
  EmpEntity: TEntity;
begin
  EmpType := Context['Emp'];
  EmpEntity := Context.CreateAttachedEntity(EmpType, [1, 1]);
  // ...
end; 
© 1997-2017 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback