Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ jobs:
uses: actions/checkout@v1

- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: |
8.0.x
10.0.x

- name: Install dependencies
run: dotnet restore
Expand All @@ -21,4 +23,4 @@ jobs:
run: dotnet build ./Mindbox.Data.Linq.sln --configuration Release --no-restore

- name: Test
run: dotnet test --no-restore
run: dotnet test --no-restore
9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<LangVersion>12</LangVersion>
<Company>Mindbox</Company>
<Authors>Mindbox</Authors>
<Copyright>Copyright 2019 (c) Mindbox</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
</Project>
17 changes: 17 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Mindbox.Expressions" Version="3.3.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.11.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.11.1" />
<PackageVersion Include="System.Security.Permissions" Version="8.0.0" />
</ItemGroup>
</Project>
20 changes: 9 additions & 11 deletions Mindbox.Data.Linq.Tests/Mindbox.Data.Linq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<RootNamespace>Mindbox.Data.Linq.Tests</RootNamespace>
<AssemblyName>Mindbox.Data.Linq.Tests</AssemblyName>
<TargetFramework>net7.0</TargetFramework>
<Deterministic>false</Deterministic>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Company>mindbox.ru</Company>
<Product>Itc.Nexus</Product>
<NeutralLanguage>ru</NeutralLanguage>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<NoWarn>CS0169</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Mindbox.Data.Linq\Mindbox.Data.Linq.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="Moq" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Data.Linq;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Mindbox.Data.Linq.Tests
{
/// <summary>
/// Tests that array.Contains(value) in LINQ queries is correctly translated to SQL IN clause.
/// In .NET 10, the C# compiler generates MemoryExtensions.Contains(ReadOnlySpan, value)
/// for this pattern instead of Enumerable.Contains — this must produce the same SQL.
/// </summary>
[TestClass]
public class ArrayContainsTranslationTests
{
[TestMethod]
public void ArrayContains_TranslatesToSqlIn()
{
var ids = new[] { 1, 2, 3 };

using var connection = new DbConnectionStub();
using var context = new DataContext(connection);

var query = context.GetTable<SimpleEntity>().Where(t => ids.Contains(t.Id));

using var command = context.GetCommand(query);

Assert.AreEqual(
"SELECT [t0].[Id], [t0].[Discriminator], [t0].[X]" + Environment.NewLine +
"FROM [SimpleTable] AS [t0]" + Environment.NewLine +
"WHERE [t0].[Id] IN (@p0, @p1, @p2)",
command.CommandText);
}

[TestMethod]
public void ArrayContains_EmptyArray_TranslatesToFalse()
{
var ids = Array.Empty<int>();

using var connection = new DbConnectionStub();
using var context = new DataContext(connection);

var query = context.GetTable<SimpleEntity>().Where(t => ids.Contains(t.Id));

using var command = context.GetCommand(query);

Assert.AreEqual(
"SELECT [t0].[Id], [t0].[Discriminator], [t0].[X]" + Environment.NewLine +
"FROM [SimpleTable] AS [t0]" + Environment.NewLine +
"WHERE 0 = 1",
command.CommandText);
}
}
}
28 changes: 10 additions & 18 deletions Mindbox.Data.Linq/Mindbox.Data.Linq.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Mindbox.Data.Linq</PackageId>
<Company>Mindbox</Company>
<TargetFramework>net8.0</TargetFramework>
<PackageId>Mindbox.Data.Linq</PackageId>
<Version>3.2.0</Version>
<Description>A clone of Microsoft System.Data.Linq to allow multi-DLL extensibility and EF compatibility.</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Copyright>Copyright 2019 (c) Mindbox</Copyright>
<Authors>Mindbox</Authors>
<LangVersion>latest</LangVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageVersion>10.7.2$(VersionTag)</PackageVersion>
<PackageVersion>10.8.0$(VersionTag)</PackageVersion>
<NoWarn>SYSLIB0003;SYSLIB0011</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
<PackageReference Include="Mindbox.Expressions" Version="3.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Security.Permissions" Version="7.0.0" />
<PackageReference Include="Castle.Core" />
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="Mindbox.Expressions" />
<PackageReference Include="System.Security.Permissions" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions Mindbox.Data.Linq/SqlClient/Query/QueryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,17 @@ private SqlNode VisitMethodCall(MethodCallExpression mc) {
if (this.IsSequenceOperatorCall(mc)) {
return this.VisitSequenceOperatorCall(mc);
}
// In .NET 10, array.Contains(value) in expression trees compiles to
// MemoryExtensions.Contains(ReadOnlySpan<T>.op_Implicit(array), value).
// Translate the same as Enumerable.Contains(array, value).
else if (mc.Method.DeclaringType == typeof(MemoryExtensions)
&& mc.Method.Name == "Contains"
&& mc.Arguments[0] is MethodCallExpression spanConversion
&& spanConversion.Method.ReturnType is { IsGenericType: true } returnType
&& returnType.GetGenericTypeDefinition() == typeof(ReadOnlySpan<>)
&& spanConversion.Arguments.Count == 1) {
return this.VisitContains(spanConversion.Arguments[0], mc.Arguments[1]);
}
else if (IsDataManipulationCall(mc)) {
return this.VisitDataManipulationCall(mc);
}
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Mindbox.Data.Linq

A fork of Microsoft's `System.Data.Linq` (LINQ to SQL) that enables multi-assembly extensibility and compatibility with modern .NET.

## Why this fork?

The original `System.Data.Linq` ships as a single sealed assembly. This fork splits the internals across multiple DLLs, making it possible to extend the query pipeline — custom SQL translators, mapping providers, and diagnostics hooks — without reflection hacks.

## Target framework

`net8.0`

## Installation

```
dotnet add package Mindbox.Data.Linq
```

## Usage

Drop-in replacement for `System.Data.Linq`. Replace the namespace import and use `DataContext` as usual:

```csharp
using System.Data.Linq;

using var context = new DataContext(connectionString, mappingSource);
var results = context.GetTable<Order>()
.Where(o => o.CustomerId == customerId)
.ToList();
```

## Key differences from System.Data.Linq

| Feature | System.Data.Linq | Mindbox.Data.Linq |
|---|---|---|
| Multi-assembly extensibility | ✗ | ✓ |
| .NET 10 `array.Contains()` in queries | ✗ | ✓ |
| Target framework | netstandard2.0 | net8.0 |

## Building

```bash
dotnet restore
dotnet build --configuration Release
dotnet test
```

## License

MIT — see [LICENSE.txt](LICENSE.txt).
Loading