Hi,
i have two table master and details as :
[Entity]
[Table('DetailsTable')]
[Id('Fid', TIdGenerator.None)]
[Id('FParentID', TIdGenerator.None)]
TDetailsTable = class
private
[Column('id', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
Fid: integer;
[Column('ItemID', [TColumnProp.Required], 20)]
FItemID: string;
[Association([TAssociationProp.Lazy, TAssociationProp.Required], [])]
[JoinColumn('ParentID', [TColumnProp.Required], 'id')]
FParentID: Proxy<TMasterTable>;
function GetParentID: TMasterTable;
procedure SetParentID(const Value: TMasterTable);
public
property id: integer read Fid write Fid;
property ItemID: string read FItemID write FItemID;
property ParentID: TMasterTable read GetParentID write SetParentID;
end;
[Entity]
[Table('MasterTable')]
[Id('Fid', TIdGenerator.None)]
TMasterTable = class
private
[Column('id', [TColumnProp.Required])]
Fid: integer;
[Column('InvDate', [])]
FInvDate: Nullable<TDateTime>;
[Column('InvNo', [TColumnProp.Required], 20)]
FInvNo: string;
[ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FParentID')]
FDetailsTableList: Proxy<TList<TDetailsTable>>;
function GetDetailsTableList: TList<TDetailsTable>;
public
constructor Create;
destructor Destroy; override;
property id: integer read Fid write Fid;
property InvDate: Nullable<TDateTime> read FInvDate write FInvDate;
property InvNo: string read FInvNo write FInvNo;
property DetailsTableList: TList<TDetailsTable> read GetDetailsTableList;
end;
I'm trying to save the data as
MasterDataset.Insert;
MasterDataset.FieldByName('id').AsInteger := 1;
MasterDataset.FieldByName('InvDate').AsDateTime := Now;
MasterDataset.FieldByName('InvNo').AsString := '1000';
MasterDataset.Post;
DetailsDataset.Insert;
DetailsDataset.FieldByName('ParentID').AsInteger := 1;
DetailsDataset.FieldByName('itemid').AsString := '2001';
DetailsDataset.Post;
but access violation error displayed, the problem occurs with the details table because the data saved in the master table without any problem, any comments or working example for how to work with master details in Aurelius?
here how i set the dataset :
FManager := TObjectManager.Create(CreateNewConnection);
InvList := FManager.Find<TMasterTable>.List;
MasterDataset.SetSourceList(InvList);
MasterDataset.Manager := FManager;
MasterDataset.Open;
DetailsDataset.DatasetField := MasterDataset.FieldByName('DetailsTableList') as TDatasetField;
DetailsDataset.Open;
also is it possible to save all the data once or cancel the operation ( How to set transaction) ?