EnableRelationIntegrity Extension Method

Overview

Enables relation integrity validation during editing for an observable data set. After enabling, the library listens to change notifications (data fields changes, row / table add / remove) and validates relations on the underlying InnerDataSet.

When violations are detected, the returned subscription raises RelationValidationFailed with details (for example, an Employee row referencing a non-existing Department).

The returned subscription is IDisposable. Always dispose it when the screen / workflow closes to detach handlers and prevent memory leaks.

Declaration

/// <summary>
/// Enables relation integrity validation during editing for an observable data set.
/// </summary>
/// <param name="observableDataSet">Observable data set</param>
/// <param name="relationValidationOptions">Relation validation options (null uses defaults).</param>
/// <returns>Subscription (IDisposable) that must be disposed when no longer needed.</returns>
public static ObservableRelationIntegritySubscription EnableRelationIntegrity(this IObservableDataSet? observableDataSet, RelationValidationOptions? relationValidationOptions)

Namespace and Assembly

Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll

Usage Example

// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();

// 2. Add Department observable data table to observable data set
IObservableDataTable departmentObservableDataTable = observableDataSet.AddNewTable("Department");
departmentObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentObservableDataTable.AddColumn("Name", DataTypeNames.STRING);

// 2. Add Employee observable data table to observable data set
IObservableDataTable employeeObservableDataTable = observableDataSet.AddNewTable("Employee");
employeeObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeObservableDataTable.AddColumn("DepartmentId", DataTypeNames.INT32, true, false, true);
employeeObservableDataTable.AddColumn("FullName", DataTypeNames.STRING);

// Create relation Department(Id) -> Employee(DepartmentId)
observableDataSet.AddRelation("FK_Employee_Department", "Department", "Id", "Employee", "DepartmentId");

// Enable relation integrity checks during editing
RelationValidationOptions options = new RelationValidationOptions();
using ObservableRelationIntegritySubscription subscription = observableDataSet.EnableRelationIntegrity(options);
subscription.RelationValidationFailed += Subscription_RelationValidationFailed;

// Add a Department
IObservableDataRow departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 1;
departmentObservableDataRow["Name"] = "Engineering";

// Add an Employee with an invalid DepartmentId (no matching Department)
IObservableDataRow employeeObservableDataRow = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow["Id"] = 100;
employeeObservableDataRow["FullName"] = "Alice";
employeeObservableDataRow["DepartmentId"] = 999; // <-- violation: Department 999 does not exist

// RelationValidationFailed will fire on edit / add events (depending on options and validation triggers)
private static void Subscription_RelationValidationFailed(object? sender, ObservableRelationValidationFailedEventArgs e)
{
    Console.WriteLine("Relation validation failed. Trigger: " + e.HandledEventName);
    Console.WriteLine("Violation count: " + e.Violations.Count);
}

 

Table of Content POCO DataSet Observable Data Set Members

 


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.