DataLinq 0.6.1

dotnet add package DataLinq --version 0.6.1
                    
NuGet\Install-Package DataLinq -Version 0.6.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DataLinq" Version="0.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DataLinq" Version="0.6.1" />
                    
Directory.Packages.props
<PackageReference Include="DataLinq" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DataLinq --version 0.6.1
                    
#r "nuget: DataLinq, 0.6.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DataLinq@0.6.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DataLinq&version=0.6.1
                    
Install as a Cake Addin
#tool nuget:?package=DataLinq&version=0.6.1
                    
Install as a Cake Tool

DataLinq

DataLinq is an lightweight, high-performance ORM using source generators that prioritizes data integrity, thread safety, and efficient caching through use of immutable models. It is designed to lean heavily on the cache to trade memory usage for speed.

Goal

The aim of the library is to minimize memory allocations and maximize speed of data retrieval, with the main focus being on read-heavy applications on small to medium projects. One focus area is to solve the classical N+1 problem, making access to related entities as close as possible to reading a local variable.

Motivation

DataLinq is an exploration of the idea of combining immutability, indirect querying and caching. It is also an exploration of using source generators to minimize the overhead of reflection usually plaguing ORM libraries.

Core Philosophy

  • Immutability First:
    All data read from the database is represented as immutable objects, ensuring thread safety and predictable behavior. When modifications are required, DataLinq provides an mechanism to create mutable copies, update them, and seamlessly synchronize the changes.
  • Efficient Caching:
    The framework leverages both global and transaction-specific caching, dramatically reducing database hits.
  • LINQ Querying:
    Built on LINQ, DataLinq translates queries into backend-specific commands without exposing you to the underlying complexities.
  • Minimize boilerplate:
    Use the CLI tool to create model classes that defines types and database structure, then DataLinq automatically generate immutable and mutable classes with the built in source generator.
  • Compile time errors:
    Move as many errors as possible from runtime to compile time. For example is setting of required fields enforced by the compiler and will give a compile time error, rather than an error when inserting to the database.
  • Extensibility:
    Although current support includes MySQL/MariaDB and SQLite, the modular architecture makes it straightforward to extend to other data sources in the future.

Getting Started

Installation

Install DataLinq via NuGet. These are the currently available backends:

dotnet add package DataLinq.MySql
dotnet add package DataLinq.SQLite

The CLI is installed as a dotnet tool:

dotnet tool install --global DataLinq.CLI

Configuration

  1. Database Connection:
    Configure your connection strings (for MySQL/MariaDB or SQLite) in your application’s configuration file.
  2. DataLinq Configuration:
    Use the provided configuration file (e.g., datalinq.json) to define your database settings.

Model Creation

Generate your data models directly from your database schema using the CLI:

datalinq create-models -n YourDatabaseName

And then to generate SQL scripts from the models:

datalinq create-sql -o output.sql -n YourDatabaseName

Code Examples & Usage

Performing a Simple Query

Retrieve all active users using LINQ:

var activeUsers = usersDb.Query().Users
    .Where(x => x.Status == UserStatus.Active)
    .ToList();

Updating Data with Immutability

Fetch an immutable record, mutate it, and then save the changes:

// Retrieve an immutable user
var user = usersDb.Query().Users.Single(u => u.Id == 1);

// Create a mutable copy, update the record, and save changes
var updatedUser = user.Mutate(u => u.Name = "New Name").Save();

Fetch a department and its associated managers:

var department = employeesDb.Query().Departments.Single(d => d.DeptNo == "d005");
var managers = department.Managers;  // Fetches collection of managers from cache

Contributing & Further Resources

Documentation

For in-depth technical details, advanced usage, and troubleshooting, please refer to the official documentation.

Contributing

We welcome contributions from the community! Whether you’re fixing bugs, improving documentation, or adding new features, your help is appreciated. Please see our Contributing Guide for details.

License

DataLinq is open source and distributed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DataLinq:

Package Downloads
DataLinq.MySql

MySQL and MariaDB support for DataLinq - a lightweight, high-performance .NET ORM using source generators for immutability and efficient caching - optimized for read-heavy applications.

DataLinq.SQLite

SQLite support for DataLinq - a lightweight, high-performance .NET ORM using source generators for immutability and efficient caching - optimized for read-heavy applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.1 169 8/5/2025
0.6.0 90 7/29/2025
0.5.4 289 6/11/2025
0.5.3 156 6/4/2025
0.5.2 160 5/19/2025
0.5.1 159 4/11/2025
0.5.0 226 4/3/2025
0.4.15 1,181 5/16/2024
0.4.14 229 2/7/2024
0.4.13 183 1/30/2024
0.4.11 499 12/4/2023
0.4.10 202 11/29/2023
0.4.9 199 11/24/2023
0.4.8 185 11/23/2023
0.4.7 222 11/1/2023
0.4.6 207 10/24/2023
0.4.5 211 10/1/2023
0.4.4 190 10/1/2023
0.4.3 177 9/29/2023
0.4.2 170 9/28/2023
0.4.1 167 9/28/2023
0.4.0 228 8/7/2023
0.3.0 777 5/3/2022
0.2.3 766 3/10/2022
0.2.2 856 2/3/2022
0.2.1 871 2/2/2022
0.2.0 869 2/1/2022
0.1.0 991 10/29/2021