Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 1ac0155

Browse files
committed
Update lowest supported linq2db to 5.4.0 (#380)
* - update dependencies - fix analyzer reports - fix non-ivariant culture uses * update icon (cherry picked from commit c0fb721) # Conflicts: # .editorconfig # Directory.Build.props # Directory.Packages.props # NuGet/linq2db.EntityFrameworkCore.nuspec # Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/JsonConverTests.cs # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ValueConversion/ConvertorTests.cs # azure-pipelines.yml (cherry picked from commit d253150) # Conflicts: # Directory.Build.props # Directory.Packages.props # NuGet/linq2db.EntityFrameworkCore.nuspec # Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs # Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs # Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/AAA.cs # Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/StringExtensions.cs # Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/Settings.cs # azure-pipelines.yml
1 parent 5ba76be commit 1ac0155

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+35169
-34973
lines changed

.editorconfig

+325-3
Large diffs are not rendered by default.

Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<Version>6.16.0</Version>
3+
<Version>6.17.0</Version>
44

55
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
66
<Product>Linq to DB</Product>
77
<Company>linq2db.net</Company>
8-
<Copyright>2002-2023 linq2db.net</Copyright>
8+
<Copyright>2002-2024 linq2db.net</Copyright>
99
<RepositoryUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</RepositoryUrl>
1010
<RepositoryType>git</RepositoryType>
1111

Directory.Packages.props

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
3+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
44
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
5-
<PackageVersion Include="NUnit" Version="3.13.3" />
5+
<PackageVersion Include="NUnit" Version="4.1.0" />
66
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
77

8-
<PackageVersion Include="linq2db" Version="5.3.1" />
9-
<PackageVersion Include="linq2db.Tools" Version="5.3.1" />
8+
<PackageVersion Include="linq2db" Version="5.4.0" />
9+
<PackageVersion Include="linq2db.Tools" Version="5.4.0" />
10+
11+
<PackageVersion Include="NUnit.Analyzers" Version="4.0.1" />
12+
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.145" />
1013

1114
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
1215

1316
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
14-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.5" />
15-
17+
18+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.27" />
1619
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
1720
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
18-
1921
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
2022
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="6.0.22" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.23" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.23" />
23+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.27" />
24+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.27" />
2325

2426
<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
25-
<PackageVersion Include="FSharp.Core" Version="7.0.400" />
2627
</ItemGroup>
2728
</Project>

NuGet/icon.png

18.6 KB
Loading

NuGet/linq2db.EntityFrameworkCore.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Linq to DB (linq2db) extensions for Entity Framework Core</title>
66
<authors>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</authors>
77
<owners>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</owners>
8-
<copyright>Copyright © 2020-2023 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
8+
<copyright>Copyright © 2020-2024 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
99
<description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</description>
1010
<summary />
1111
<tags>linq linq2db LinqToDB ORM database entity-framework-core EntityFrameworkCore EFCore DB SQL SqlServer SqlCe SqlServerCe MySql Firebird SQLite Oracle ODP PostgreSQL DB2</tags>
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework="net6.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.5" />
19-
<dependency id="linq2db" version="5.3.1" />
19+
<dependency id="linq2db" version="5.4.0" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

+15-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace LinqToDB.EntityFrameworkCore
1919
{
20+
using System.Globalization;
2021
using Common;
2122
using Expressions;
2223
using Extensions;
@@ -52,7 +53,7 @@ public EFCoreMetadataReader(IModel? model, IInfrastructure<IServiceProvider>? ac
5253
_logger = accessor.GetService<IDiagnosticsLogger<DbLoggerCategory.Query>>();
5354
}
5455

55-
_objectId = $".{_model?.GetHashCode() ?? 0}.{_dependencies?.GetHashCode() ?? 0}.{_mappingSource?.GetHashCode() ?? 0}.{_annotationProvider?.GetHashCode() ?? 0}.{_logger?.GetHashCode() ?? 0}.";
56+
_objectId = FormattableString.Invariant($".{_model?.GetHashCode() ?? 0}.{_dependencies?.GetHashCode() ?? 0}.{_mappingSource?.GetHashCode() ?? 0}.{_annotationProvider?.GetHashCode() ?? 0}.{_logger?.GetHashCode() ?? 0}.");
5657
}
5758

5859
public MappingAttribute[] GetAttributes(Type type)
@@ -124,10 +125,10 @@ public MappingAttribute[] GetAttributes(Type type)
124125
// TableAttribute
125126
var tableAttribute = type.GetAttribute<System.ComponentModel.DataAnnotations.Schema.TableAttribute>();
126127
if (tableAttribute != null)
127-
(result ??= new()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
128+
(result = new ()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
128129
}
129130

130-
return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
131+
return result == null ? [] : result.ToArray();
131132
}
132133

133134
static IEntityType GetBaseTypeRecursive(IEntityType entityType)
@@ -221,7 +222,7 @@ static DataType DbTypeToDataType(DbType dbType)
221222
public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
222223
{
223224
if (typeof(Expression).IsSameOrParentOf(type))
224-
return Array.Empty<MappingAttribute>();
225+
return [];
225226

226227
List<MappingAttribute>? result = null;
227228
var hasColumn = false;
@@ -269,7 +270,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
269270
.Any(static a =>
270271
{
271272
if (a.Name.EndsWith(":ValueGenerationStrategy"))
272-
return a.Value?.ToString()?.Contains("Identity") == true;
273+
return a.Value != null && string.Format(CultureInfo.InvariantCulture, "{0}", a.Value).Contains("Identity");
273274

274275
if (a.Name.EndsWith(":Autoincrement"))
275276
return a.Value is bool b && b;
@@ -279,7 +280,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
279280
{
280281
if (a.Value is string str)
281282
{
282-
return str.ToLowerInvariant().Contains("nextval");
283+
return str.Contains("nextval", StringComparison.OrdinalIgnoreCase);
283284
}
284285
}
285286

@@ -432,7 +433,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
432433
});
433434
}
434435

435-
return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
436+
return result == null ? [] : result.ToArray();
436437
}
437438

438439
sealed class ValueConverter : IValueConverter
@@ -598,7 +599,7 @@ string PrepareExpressionText(Expression? expr)
598599
}
599600

600601
if (idx >= 0)
601-
return $"{{{idx}}}";
602+
return FormattableString.Invariant($"{{{idx}}}");
602603

603604
if (expr is SqlFragmentExpression fragment)
604605
return fragment.Sql;
@@ -611,16 +612,16 @@ string PrepareExpressionText(Expression? expr)
611612

612613
if (!sqlFunction.IsNiladic)
613614
{
614-
text = text + "(";
615+
text += "(";
615616
for (var i = 0; i < sqlFunction.Arguments.Count; i++)
616617
{
617618
var paramText = PrepareExpressionText(sqlFunction.Arguments[i]);
618619
if (i > 0)
619-
text = text + ", ";
620-
text = text + paramText;
620+
text += ", ";
621+
text += paramText;
621622
}
622623

623-
text = text + ")";
624+
text += ")";
624625
}
625626

626627
return text;
@@ -634,7 +635,7 @@ string PrepareExpressionText(Expression? expr)
634635
var left = (Expression)newExpression.GetType().GetProperty("Left")!.GetValue(newExpression)!;
635636
var right = (Expression)newExpression.GetType().GetProperty("Right")!.GetValue(newExpression)!;
636637

637-
var operand = newExpression.GetType().GetProperty("OperatorType")!.GetValue(newExpression)!.ToString()!;
638+
var operand = string.Format(CultureInfo.InvariantCulture, "{0}", newExpression.GetType().GetProperty("OperatorType")!.GetValue(newExpression));
638639

639640
var operandExpr = operand switch
640641
{
@@ -714,7 +715,7 @@ private static Expression UnwrapConverted(Expression expr)
714715

715716
public MemberInfo[] GetDynamicColumns(Type type)
716717
{
717-
return Array.Empty<MemberInfo>();
718+
return [];
718719
}
719720

720721
string IMetadataReader.GetObjectID() => _objectId;

Source/LinqToDB.EntityFrameworkCore/Internal/EFCoreExpressionAttribute.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Linq.Expressions;
56
using LinqToDB.Mapping;
@@ -10,7 +11,7 @@ namespace LinqToDB.EntityFrameworkCore.Internal
1011
/// <summary>
1112
/// Maps Linq To DB expression.
1213
/// </summary>
13-
public class EFCoreExpressionAttribute : Sql.ExpressionAttribute
14+
public sealed class EFCoreExpressionAttribute : Sql.ExpressionAttribute
1415
{
1516
/// <summary>
1617
/// Creates instance of expression mapper.
@@ -47,7 +48,7 @@ public EFCoreExpressionAttribute(string expression) : base(expression)
4748
_ = ResolveExpressionValues((context, parms, knownExpressions, converter), Expression!,
4849
static (ctx, v, d) =>
4950
{
50-
var idx = int.Parse(v);
51+
var idx = int.Parse(v, CultureInfo.InvariantCulture);
5152

5253
if (ctx.parms[idx] == null)
5354
ctx.parms[idx] = ctx.converter(ctx.context, ctx.knownExpressions[idx], null);

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LinqToDBForEFQueryProvider<T> : IAsyncQueryProvider, IQueryProvider
3333
/// <param name="expression">Query expression.</param>
3434
public LinqToDBForEFQueryProvider(IDataContext dataContext, Expression expression)
3535
{
36-
if (expression == null) throw new ArgumentNullException(nameof(expression));
36+
ArgumentNullException.ThrowIfNull(expression);
3737
var dataContext1 = dataContext ?? throw new ArgumentNullException(nameof(dataContext));
3838
QueryProvider = (IQueryProviderAsync) Internals.CreateExpressionQueryInstance<T>(dataContext1, expression);
3939
QueryProviderAsQueryable = (IQueryable<T>) QueryProvider;
@@ -110,7 +110,7 @@ TResult IAsyncQueryProvider.ExecuteAsync<TResult>(Expression expression, Cancell
110110
{
111111
var item = typeof(TResult).GetGenericArguments()[0];
112112
var method = _executeAsyncMethodInfo.MakeGenericMethod(item);
113-
return (TResult) method.Invoke(QueryProvider, new object[] { expression, cancellationToken })!;
113+
return (TResult)method.Invoke(QueryProvider, [expression, cancellationToken])!;
114114
}
115115

116116
/// <summary>

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.ContextExtensions.cs

+25-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static partial class LinqToDBForEFTools
2626
/// <returns>Bulk insert operation status.</returns>
2727
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, BulkCopyOptions options, IEnumerable<T> source) where T : class
2828
{
29-
if (context == null) throw new ArgumentNullException(nameof(context));
29+
ArgumentNullException.ThrowIfNull(context);
3030

3131
using (var dc = context.CreateLinqToDBConnection())
3232
{
@@ -44,7 +44,7 @@ public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, BulkCopyOpt
4444
/// <returns>Bulk insert operation status.</returns>
4545
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, int maxBatchSize, IEnumerable<T> source) where T : class
4646
{
47-
if (context == null) throw new ArgumentNullException(nameof(context));
47+
ArgumentNullException.ThrowIfNull(context);
4848

4949
using (var dc = context.CreateLinqToDBConnection())
5050
{
@@ -63,7 +63,7 @@ public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, int maxBatc
6363
/// <returns>Bulk insert operation status.</returns>
6464
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, IEnumerable<T> source) where T : class
6565
{
66-
if (context == null) throw new ArgumentNullException(nameof(context));
66+
ArgumentNullException.ThrowIfNull(context);
6767

6868
using (var dc = context.CreateLinqToDBConnection())
6969
{
@@ -91,8 +91,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
9191
CancellationToken cancellationToken = default)
9292
where T : class
9393
{
94-
if (context == null) throw new ArgumentNullException(nameof(context));
95-
if (source == null) throw new ArgumentNullException(nameof(source));
94+
ArgumentNullException.ThrowIfNull(context);
95+
ArgumentNullException.ThrowIfNull(source);
9696

9797
using (var dc = context.CreateLinqToDBConnection())
9898
{
@@ -117,11 +117,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
117117
CancellationToken cancellationToken = default)
118118
where T : class
119119
{
120-
if (context == null) throw new ArgumentNullException(nameof(context));
121-
if (source == null) throw new ArgumentNullException(nameof(source));
122-
123-
if (context == null) throw new ArgumentNullException(nameof(context));
124-
if (source == null) throw new ArgumentNullException(nameof(source));
120+
ArgumentNullException.ThrowIfNull(context);
121+
ArgumentNullException.ThrowIfNull(source);
125122

126123
using (var dc = context.CreateLinqToDBConnection())
127124
{
@@ -141,8 +138,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
141138
CancellationToken cancellationToken = default)
142139
where T : class
143140
{
144-
if (context == null) throw new ArgumentNullException(nameof(context));
145-
if (source == null) throw new ArgumentNullException(nameof(source));
141+
ArgumentNullException.ThrowIfNull(context);
142+
ArgumentNullException.ThrowIfNull(source);
146143

147144
using (var dc = context.CreateLinqToDBConnection())
148145
{
@@ -164,8 +161,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
164161
CancellationToken cancellationToken = default)
165162
where T : class
166163
{
167-
if (context == null) throw new ArgumentNullException(nameof(context));
168-
if (source == null) throw new ArgumentNullException(nameof(source));
164+
ArgumentNullException.ThrowIfNull(context);
165+
ArgumentNullException.ThrowIfNull(source);
169166

170167
using (var dc = context.CreateLinqToDBConnection())
171168
{
@@ -190,8 +187,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
190187
CancellationToken cancellationToken = default)
191188
where T : class
192189
{
193-
if (context == null) throw new ArgumentNullException(nameof(context));
194-
if (source == null) throw new ArgumentNullException(nameof(source));
190+
ArgumentNullException.ThrowIfNull(context);
191+
ArgumentNullException.ThrowIfNull(source);
195192

196193
using (var dc = context.CreateLinqToDBConnection())
197194
{
@@ -211,8 +208,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
211208
CancellationToken cancellationToken = default)
212209
where T : class
213210
{
214-
if (context == null) throw new ArgumentNullException(nameof(context));
215-
if (source == null) throw new ArgumentNullException(nameof(source));
211+
ArgumentNullException.ThrowIfNull(context);
212+
ArgumentNullException.ThrowIfNull(source);
216213

217214
using (var dc = context.CreateLinqToDBConnection())
218215
{
@@ -236,10 +233,12 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
236233
public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> target)
237234
where T: notnull
238235
{
239-
if (context == null) throw new ArgumentNullException(nameof(context));
240-
if (target == null) throw new ArgumentNullException(nameof(target));
236+
ArgumentNullException.ThrowIfNull(context);
237+
ArgumentNullException.ThrowIfNull(target);
241238

239+
#pragma warning disable CA2000 // Dispose objects before losing scope
242240
return context.CreateLinqToDBConnection().Into(target);
241+
#pragma warning restore CA2000 // Dispose objects before losing scope
243242
}
244243

245244
#endregion
@@ -254,9 +253,11 @@ public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> targ
254253
public static ITable<T> GetTable<T>(this DbContext context)
255254
where T : class
256255
{
257-
if (context == null) throw new ArgumentNullException(nameof(context));
256+
ArgumentNullException.ThrowIfNull(context);
258257

258+
#pragma warning disable CA2000 // Dispose objects before losing scope
259259
return context.CreateLinqToDBContext().GetTable<T>();
260+
#pragma warning restore CA2000 // Dispose objects before losing scope
260261
}
261262

262263
#endregion
@@ -268,9 +269,8 @@ public static ITable<T> GetTable<T>(this DbContext context)
268269
/// </summary>
269270
/// <returns>Db context object.</returns>
270271
public static DataOptions? GetLinqToDBOptions(this DbContext context)
271-
272272
{
273-
if (context == null) throw new ArgumentNullException(nameof(context));
273+
ArgumentNullException.ThrowIfNull(context);
274274

275275
var contextOptions = ((IInfrastructure<IServiceProvider>)context.Database)?
276276
.Instance?.GetService(typeof(IDbContextOptions)) as IDbContextOptions;
@@ -284,9 +284,9 @@ public static ITable<T> GetTable<T>(this DbContext context)
284284
/// <returns>Db context options.</returns>
285285
public static DataOptions? GetLinqToDBOptions(this IDbContextOptions contextOptions)
286286
{
287-
if (contextOptions == null) throw new ArgumentNullException(nameof(contextOptions));
287+
ArgumentNullException.ThrowIfNull(contextOptions);
288288

289-
return contextOptions?.FindExtension<LinqToDBOptionsExtension>()?.Options;
289+
return contextOptions.FindExtension<LinqToDBOptionsExtension>()?.Options;
290290
}
291291

292292
#endregion

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.Extensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static ITable<T> ToLinqToDBTable<T>(this DbSet<T> dbSet)
1515
{
1616
var context = Implementation.GetCurrentContext(dbSet)
1717
?? throw new LinqToDBForEFToolsException($"Can not load current context from {nameof(dbSet)}");
18+
#pragma warning disable CA2000 // Dispose objects before losing scope
1819
var dc = CreateLinqToDBContext(context);
20+
#pragma warning restore CA2000 // Dispose objects before losing scope
1921
return dc.GetTable<T>();
2022
}
2123

0 commit comments

Comments
 (0)