EntityDAC

TCustomEntityContext.CreateAttachedEntity<T> Method

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

Class

TCustomEntityContext

Syntax

function CreateAttachedEntity<T: TMappedEntity>(Key: TPrimaryKey): T; overload;

Type parameters
T
The class type of the entity to be created
Parameters
Key
The primary key for the entity to be created.

Remarks

The method creates a new entity instance of the specified class type with the specified primary key. 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
  PK: TPrimaryKey;
  EmpEntity: TEntity;
begin
  PK := TPrimaryKey.Create(Context['Emp']);
  PK.Values[0].AsInteger := 1;
EmpEntity := Context.CreateAttachedEntity<TEmp>(PK);
  // ...
end; 

See Also

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