Entity Framework Core Bridge Types

Overview

The EF Core Bridge category only has one type, EfCoreMergeAdapter. It provides a way to load data from a database into a dataset using the LoadData method and save data from a dataset to the database using the SaveData method. There are two overloads of the LoadData method. The first is useful for loading data from a single table in the database. The second is useful for loading data from multiple tables in the database.

Declaration

/// <summary>
/// Loads data into data set for an initial UI baseline or full refresh, returning a snapshot dataset that can be merged into the UI baseline.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
/// <param name="dbContext">DB context</param>
/// <param name="efQuery">Entity Framework query</param>
/// <param name="tableName">Table name</param>
/// <returns>Data set with loaded data</returns>
public static IDataSet LoadData(DbContext dbContext, IQueryable efQuery, string tableName) where TEntity : class

/// <summary>
/// Loads data into data set for an initial UI baseline or full refresh, returning a snapshot dataset that can be merged into the UI baseline.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
/// <param name="dbContext">DB context</param>
/// <param name="efQuery">Entity Framework query</param>
/// <param name="targetDataSet">Target data set</param>
/// <param name="tableName">Table name</param>
/// <exception cref="ArgumentNullException">Thrown if table name is not provided</exception>
public static void LoadData(DbContext dbContext, IQueryable efQuery, IDataSet targetDataSet, string tableName) where TEntity : class

/// <summary>
/// Saves data and returns post-save data set with server-confirmed values (e.g. identity column values, concurrency tokens, etc.) after save.
/// </summary>
/// <param name="dbContext">DB context</param>
/// <param name="changeset">Change set</param>
/// <returns>Result of saving - the post-save data set</returns>
public static IDataSet SaveData(DbContext dbContext, IDataSet changeset)

Namespace and Assembly

Namespace: PocoDataSet.EfCoreBridge
Assembly: PocoDataSet.EfCoreBridge.dll

Usage Example

Loading data from database

a) Example of loading data from 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 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);

Saving data to database

Assuming changeset is a dataset representing changes to be saved to the database, for example created by calling CreateChangeset() on an observable dataset after user edits in the UI:

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

Note

You can look at "POCO DataSet" > "Quick Start" > "EF Core Integration – Recommended Lifecycle" page for complete end-to-end example.

 

Table of Content POCO DataSet API References

 


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.