EntityDAC

Extend the Application to Show Master-Detail Datasets



In this part of the tutorial we continue to develop our application.

Step 1

First, place another TDBGrid on the main form. Then, place TEntityDataSet component from the "EntityDAC" component palette, and the TDataSource component. Name the components as shown below. Set the DataSource property of TDBGrid to "DetailSource", and the DetailSource.DataSet property to "DetailDataSet".

Step 2

Extend the Button1.OnClick event handler as shown below:

procedure TDemoMainForm.Button1Click(Sender: TObject);
var
  Depts: ILinqQueryable;
  Emps: ILinqQueryable;
begin
  Depts := Linq.From(DemoDataModule.EntityContext1['Dept']).Select;
  MasterDataSet.SourceCollection := DemoDataModule.EntityContext1.GetEntities(Depts);

  Emps := Linq.From(DemoDataModule.EntityContext1['Emp']).Select;
  DetailDataSet.SourceCollection := DemoDataModule.EntityContext1.GetEntities(Emps);

  DetailDataSet.Open;
  MasterDataSet.Open;
end;

Step 3

Finally, set up the master-detail relationship between MasterDataSet and DetailDataSet.

Step 4

Now we are ready to test our application. Compile and run the project, and press the "Open" button.

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