In this part of the tutorial we continue to develop our application.
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".
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;
Finally, set up the master-detail relationship between MasterDataSet and DetailDataSet.
Now we are ready to test our application. Compile and run the project, and press the "Open" button.