EF Core Bridge Quick Start

EF Core Integration – Recommended Lifecycle

This page shows how the EF Core Bridge can be part of the following scenario in steps 1 and 5:

  1. Loading data from the database
  2. Replacing bound data in the UI with the loaded data
  3. Editing data in the UI
  4. Saving the modified data back to the database
  5. Merging the save result with bound data in the UI

End-to-end example

1. Using the EF Core Bridge to load data from the database to replace the data displayed in the user interface.

a) Example of loading data from database when UI is bound to one table only.

using var loadContext = new AppDbContext();

IDataSet baselineDataSet = EfCoreMergeAdapter.LoadData(loadContext, loadContext.Departments.AsNoTracking().OrderBy(x => x.Name), "Department");

b) Example of loading data from database when UI is bound to multiple tables.

using var loadContext = new AppDbContext();

IDataSet baselineDataSet = DataSetFactory.CreateDataSet();

EfCoreMergeAdapter.LoadData(loadContext, loadContext.Departments.AsNoTracking().OrderBy(x => x.Name), baselineDataSet, "Department");
EfCoreMergeAdapter.LoadData(loadContext, loadContext.Employees.AsNoTracking().OrderBy(x => x.LastName).ThenBy(x => x.FirstName), baselineDataSet, "Employee");

baselineDataSet.ApplyEfModelKeysAndRelations(loadContext);

2. Assuming observable data set is used for UI binding, for example:

IObservableDataSet boundObservableDataSet = new ObservableDataSet();

// The following line is a pseudo-code example of how UI can be bound to the observable data set.
// The actual binding code depends on the UI framework and is not part of POCO DataSet.
somePage.DataContext = boundObservableDataSet;

Replace the data in the bound observable dataset with the loaded baseline dataset:

IObservableMergeOptions observableMergeOptions = new ObservableMergeOptions();
boundObservableDataSet.DoReplaceMerge(baselineDataSet, observableMergeOptions);

3. User edits data in the UI, which modifies the observable dataset and tracks changes. After modifications, call CreateChangeset() to get a dataset representing only the changes:

IDataSet changeset = boundObservableDataSet.CreateChangeset();

4. Using the EF Core Bridge to apply the changeset to the database and return post-save data set with server-confirmed values (e.g. identity column values, concurrency tokens, etc.) after save.

using var saveContext = new AppDbContext();
IDataSet postSaveDataSet = EfCoreMergeAdapter.SaveData(saveContext, changeset);

The post-save data set is a delta dataset. It is not a "reload everything". It contains only:

5. Call DoPostSaveMerge method of observable data set to merge the server-confirmed values back into the UI baseline and finalize row states.

IObservableMergeOptions options = new ObservableMergeOptions();
boundObservableDataSet.DoPostSaveMerge(postSaveDataSet, options);

Best practices

 

Table of Content POCO DataSet Quick Start

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.