MSDN Documentation

SQL Data Control Overview

The SQL Data Control library provides a set of high‑level abstractions for managing data access, validation, and transactional workflows in Microsoft SQL Server environments. It streamlines common patterns such as CRUD operations, concurrency handling, and bulk data processing while offering extensibility for custom business rules.

General
Features
Code Sample

Key Concepts

  • DataControlContext: Central hub for configuring connections, logging, and transaction scopes.
  • EntityController: Generic controller that implements ICrudOperations for a specific entity type.
  • ValidatorPipeline: Chainable validators that enforce business rules before persisting data.
  • Auditing: Automatic creation of audit trails for inserts, updates, and deletions.

Supported Features

FeatureDescription
CRUD OperationsStandard create, read, update, delete with async support.
Batch ProcessingEfficient bulk insert/update/delete with transaction safety.
Optimistic ConcurrencyRowVersion handling to prevent lost updates.
Soft DeleteMark records as inactive without physical removal.
Dynamic FilteringExpression‑based queries built at runtime.
Built‑in AuditingAuto‑populate CreatedBy, CreatedAt, ModifiedBy, ModifiedAt.

Quick Start

// Initialize the DataControl context
var context = new DataControlContext(connectionString);

// Define a simple validator
var validator = new ValidatorPipeline<Customer>()
    .AddRule(c => !string.IsNullOrWhiteSpace(c.Name), "Name is required")
    .AddRule(c => c.Email.Contains("@"), "Invalid email");

// Create a controller for the Customer entity
var customerCtrl = new EntityController<Customer>(context, validator);

// Async create operation
await customerCtrl.CreateAsync(new Customer { Name = "Alice", Email = "alice@example.com" });

// Query with filtering
var activeCustomers = await customerCtrl.QueryAsync(c => c.IsActive);

// Update with concurrency check
var customer = await customerCtrl.GetByIdAsync(1);
customer.Email = "alice@newdomain.com";
await customerCtrl.UpdateAsync(customer);

Getting Started

To begin using the SQL Data Control library, install the NuGet package:

Install-Package SqlDataControl

Reference the namespace in your project:

using SqlDataControl;