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(EntityClass: TMappedEntityClass; const KeyValue: Variant): TMappedEntity; overload;

Parameters
EntityClass
The class type of the entity to be created
KeyValue
The initial value of the primary key meta attribute.

Remarks

The method creates a new entity instance of the specified meta-type. The entity primary key attribute will be initialized by the specified 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.Save, TCustomEntityContext.Cancel, without pre-calling TCustomEntityContext.Attach.

Example

var
  EmpEntity: TEntity;
begin
  EmpEntity := Context.CreateAttachedEntity(TEmp, 1);
  // ...
end; 

See Also

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