Skip to content

Commit

Permalink
Update lowest supported linq2db to 5.4.0 (#380)
Browse files Browse the repository at this point in the history
* - 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
  • Loading branch information
MaceWindu committed Mar 4, 2024
1 parent 5ba76be commit 1ac0155
Show file tree
Hide file tree
Showing 46 changed files with 35,169 additions and 34,973 deletions.
328 changes: 325 additions & 3 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>6.16.0</Version>
<Version>6.17.0</Version>

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

Expand Down
21 changes: 11 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />

<PackageVersion Include="linq2db" Version="5.3.1" />
<PackageVersion Include="linq2db.Tools" Version="5.3.1" />
<PackageVersion Include="linq2db" Version="5.4.0" />
<PackageVersion Include="linq2db.Tools" Version="5.4.0" />

<PackageVersion Include="NUnit.Analyzers" Version="4.0.1" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.145" />

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

<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.5" />


<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.27" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />

<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="6.0.22" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.23" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.23" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.27" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.27" />

<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
<PackageVersion Include="FSharp.Core" Version="7.0.400" />
</ItemGroup>
</Project>
Binary file modified NuGet/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions NuGet/linq2db.EntityFrameworkCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Linq to DB (linq2db) extensions for Entity Framework Core</title>
<authors>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</authors>
<owners>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</owners>
<copyright>Copyright © 2020-2023 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
<copyright>Copyright © 2020-2024 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
<description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</description>
<summary />
<tags>linq linq2db LinqToDB ORM database entity-framework-core EntityFrameworkCore EFCore DB SQL SqlServer SqlCe SqlServerCe MySql Firebird SQLite Oracle ODP PostgreSQL DB2</tags>
Expand All @@ -16,7 +16,7 @@
<dependencies>
<group targetFramework="net6.0">
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.5" />
<dependency id="linq2db" version="5.3.1" />
<dependency id="linq2db" version="5.4.0" />
</group>
</dependencies>
</metadata>
Expand Down
29 changes: 15 additions & 14 deletions Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace LinqToDB.EntityFrameworkCore
{
using System.Globalization;
using Common;
using Expressions;
using Extensions;
Expand Down Expand Up @@ -52,7 +53,7 @@ public EFCoreMetadataReader(IModel? model, IInfrastructure<IServiceProvider>? ac
_logger = accessor.GetService<IDiagnosticsLogger<DbLoggerCategory.Query>>();
}

_objectId = $".{_model?.GetHashCode() ?? 0}.{_dependencies?.GetHashCode() ?? 0}.{_mappingSource?.GetHashCode() ?? 0}.{_annotationProvider?.GetHashCode() ?? 0}.{_logger?.GetHashCode() ?? 0}.";
_objectId = FormattableString.Invariant($".{_model?.GetHashCode() ?? 0}.{_dependencies?.GetHashCode() ?? 0}.{_mappingSource?.GetHashCode() ?? 0}.{_annotationProvider?.GetHashCode() ?? 0}.{_logger?.GetHashCode() ?? 0}.");
}

public MappingAttribute[] GetAttributes(Type type)
Expand Down Expand Up @@ -124,10 +125,10 @@ public MappingAttribute[] GetAttributes(Type type)
// TableAttribute
var tableAttribute = type.GetAttribute<System.ComponentModel.DataAnnotations.Schema.TableAttribute>();
if (tableAttribute != null)
(result ??= new()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
(result = new ()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
}

return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
return result == null ? [] : result.ToArray();
}

static IEntityType GetBaseTypeRecursive(IEntityType entityType)
Expand Down Expand Up @@ -221,7 +222,7 @@ static DataType DbTypeToDataType(DbType dbType)
public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
{
if (typeof(Expression).IsSameOrParentOf(type))
return Array.Empty<MappingAttribute>();
return [];

List<MappingAttribute>? result = null;
var hasColumn = false;
Expand Down Expand Up @@ -269,7 +270,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
.Any(static a =>
{
if (a.Name.EndsWith(":ValueGenerationStrategy"))
return a.Value?.ToString()?.Contains("Identity") == true;
return a.Value != null && string.Format(CultureInfo.InvariantCulture, "{0}", a.Value).Contains("Identity");
if (a.Name.EndsWith(":Autoincrement"))
return a.Value is bool b && b;
Expand All @@ -279,7 +280,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
{
if (a.Value is string str)
{
return str.ToLowerInvariant().Contains("nextval");
return str.Contains("nextval", StringComparison.OrdinalIgnoreCase);
}
}
Expand Down Expand Up @@ -432,7 +433,7 @@ public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
});
}

return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
return result == null ? [] : result.ToArray();
}

sealed class ValueConverter : IValueConverter
Expand Down Expand Up @@ -598,7 +599,7 @@ string PrepareExpressionText(Expression? expr)
}

if (idx >= 0)
return $"{{{idx}}}";
return FormattableString.Invariant($"{{{idx}}}");

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

if (!sqlFunction.IsNiladic)
{
text = text + "(";
text += "(";
for (var i = 0; i < sqlFunction.Arguments.Count; i++)
{
var paramText = PrepareExpressionText(sqlFunction.Arguments[i]);
if (i > 0)
text = text + ", ";
text = text + paramText;
text += ", ";
text += paramText;
}

text = text + ")";
text += ")";
}

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

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

var operandExpr = operand switch
{
Expand Down Expand Up @@ -714,7 +715,7 @@ private static Expression UnwrapConverted(Expression expr)

public MemberInfo[] GetDynamicColumns(Type type)
{
return Array.Empty<MemberInfo>();
return [];
}

string IMetadataReader.GetObjectID() => _objectId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using LinqToDB.Mapping;
Expand All @@ -10,7 +11,7 @@ namespace LinqToDB.EntityFrameworkCore.Internal
/// <summary>
/// Maps Linq To DB expression.
/// </summary>
public class EFCoreExpressionAttribute : Sql.ExpressionAttribute
public sealed class EFCoreExpressionAttribute : Sql.ExpressionAttribute
{
/// <summary>
/// Creates instance of expression mapper.
Expand Down Expand Up @@ -47,7 +48,7 @@ public EFCoreExpressionAttribute(string expression) : base(expression)
_ = ResolveExpressionValues((context, parms, knownExpressions, converter), Expression!,
static (ctx, v, d) =>
{
var idx = int.Parse(v);
var idx = int.Parse(v, CultureInfo.InvariantCulture);
if (ctx.parms[idx] == null)
ctx.parms[idx] = ctx.converter(ctx.context, ctx.knownExpressions[idx], null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LinqToDBForEFQueryProvider<T> : IAsyncQueryProvider, IQueryProvider
/// <param name="expression">Query expression.</param>
public LinqToDBForEFQueryProvider(IDataContext dataContext, Expression expression)
{
if (expression == null) throw new ArgumentNullException(nameof(expression));
ArgumentNullException.ThrowIfNull(expression);
var dataContext1 = dataContext ?? throw new ArgumentNullException(nameof(dataContext));
QueryProvider = (IQueryProviderAsync) Internals.CreateExpressionQueryInstance<T>(dataContext1, expression);
QueryProviderAsQueryable = (IQueryable<T>) QueryProvider;
Expand Down Expand Up @@ -110,7 +110,7 @@ TResult IAsyncQueryProvider.ExecuteAsync<TResult>(Expression expression, Cancell
{
var item = typeof(TResult).GetGenericArguments()[0];
var method = _executeAsyncMethodInfo.MakeGenericMethod(item);
return (TResult) method.Invoke(QueryProvider, new object[] { expression, cancellationToken })!;
return (TResult)method.Invoke(QueryProvider, [expression, cancellationToken])!;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class LinqToDBForEFTools
/// <returns>Bulk insert operation status.</returns>
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, BulkCopyOptions options, IEnumerable<T> source) where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
ArgumentNullException.ThrowIfNull(context);

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

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

using (var dc = context.CreateLinqToDBConnection())
{
Expand Down Expand Up @@ -91,8 +91,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

using (var dc = context.CreateLinqToDBConnection())
{
Expand All @@ -117,11 +117,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));

if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

using (var dc = context.CreateLinqToDBConnection())
{
Expand All @@ -141,8 +138,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

using (var dc = context.CreateLinqToDBConnection())
{
Expand All @@ -164,8 +161,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

using (var dc = context.CreateLinqToDBConnection())
{
Expand All @@ -190,8 +187,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

using (var dc = context.CreateLinqToDBConnection())
{
Expand All @@ -211,8 +208,8 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
CancellationToken cancellationToken = default)
where T : class
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (source == null) throw new ArgumentNullException(nameof(source));
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(source);

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

#pragma warning disable CA2000 // Dispose objects before losing scope
return context.CreateLinqToDBConnection().Into(target);
#pragma warning restore CA2000 // Dispose objects before losing scope
}

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

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

#endregion
Expand All @@ -268,9 +269,8 @@ public static ITable<T> GetTable<T>(this DbContext context)
/// </summary>
/// <returns>Db context object.</returns>
public static DataOptions? GetLinqToDBOptions(this DbContext context)

{
if (context == null) throw new ArgumentNullException(nameof(context));
ArgumentNullException.ThrowIfNull(context);

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

return contextOptions?.FindExtension<LinqToDBOptionsExtension>()?.Options;
return contextOptions.FindExtension<LinqToDBOptionsExtension>()?.Options;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public static ITable<T> ToLinqToDBTable<T>(this DbSet<T> dbSet)
{
var context = Implementation.GetCurrentContext(dbSet)
?? throw new LinqToDBForEFToolsException($"Can not load current context from {nameof(dbSet)}");
#pragma warning disable CA2000 // Dispose objects before losing scope
var dc = CreateLinqToDBContext(context);
#pragma warning restore CA2000 // Dispose objects before losing scope
return dc.GetTable<T>();
}

Expand Down
Loading

0 comments on commit 1ac0155

Please sign in to comment.