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
(cherry picked from commit 1ac0155)

# Conflicts:
#	Directory.Build.props
#	Directory.Packages.props
#	NuGet/linq2db.EntityFrameworkCore.nuspec
#	Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs
#	Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs
#	Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/SampleTests/AAA.cs
#	Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs
#	azure-pipelines.yml
  • Loading branch information
MaceWindu committed Mar 4, 2024
1 parent bc53554 commit 3c27d7f
Show file tree
Hide file tree
Showing 45 changed files with 35,226 additions and 35,024 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>5.18.0</Version>
<Version>5.19.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
15 changes: 8 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<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="3.14.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="PolySharp" Version="1.13.2" />

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

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

<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />

<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.4" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="5.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.17" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />

<PackageVersion Include="EntityFrameworkCore.FSharp" Version="5.0.3" />
<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="netstandard2.1">
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.17" />
<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 @@ -108,7 +108,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 @@ -120,9 +120,6 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
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));

using (var dc = context.CreateLinqToDBConnection())
{
return await dc.BulkCopyAsync(maxBatchSize, source, cancellationToken).ConfigureAwait(Common.Configuration.ContinueOnCapturedContext);
Expand Down Expand Up @@ -239,7 +236,9 @@ public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> targ
if (context == null) throw new ArgumentNullException(nameof(context));
if (target == null) throw new ArgumentNullException(nameof(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 @@ -256,7 +255,9 @@ public static ITable<T> GetTable<T>(this DbContext context)
{
if (context == null) throw new ArgumentNullException(nameof(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,7 +269,6 @@ 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));

Expand All @@ -286,7 +286,7 @@ public static ITable<T> GetTable<T>(this DbContext context)
{
if (contextOptions == null) throw new ArgumentNullException(nameof(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
21 changes: 10 additions & 11 deletions Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ static void InitializeMapping()

static Sql.DateParts? GetDatePart(string name)
{
switch (name)
return name switch
{
case "Year" : return Sql.DateParts.Year;
case "Day" : return Sql.DateParts.Day;
case "Month" : return Sql.DateParts.Month;
case "Hour" : return Sql.DateParts.Hour;
case "Minute" : return Sql.DateParts.Minute;
case "Second" : return Sql.DateParts.Second;
case "Millisecond": return Sql.DateParts.Millisecond;
}

return null;
"Year" => (Sql.DateParts?)Sql.DateParts.Year,
"Day" => (Sql.DateParts?)Sql.DateParts.Day,
"Month" => (Sql.DateParts?)Sql.DateParts.Month,
"Hour" => (Sql.DateParts?)Sql.DateParts.Hour,
"Minute" => (Sql.DateParts?)Sql.DateParts.Minute,
"Second" => (Sql.DateParts?)Sql.DateParts.Second,
"Millisecond" => (Sql.DateParts?)Sql.DateParts.Millisecond,
_ => null,
};
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static bool InitializeInternal()
var newExpression = queryable.Expression;
var result = (IQueryable)instantiator.MakeGenericMethod(queryable.ElementType)
.Invoke(null, new object[] { dc, newExpression });
.Invoke(null, [dc, newExpression])!;
if (prev != null)
result = prev(result);
Expand Down Expand Up @@ -268,7 +268,7 @@ public static DataConnection CreateLinqToDBConnection(this DbContext context,

DataConnection? dc = null;

transaction = transaction ?? context.Database.CurrentTransaction;
transaction ??= context.Database.CurrentTransaction;

var connectionInfo = GetConnectionInfo(info);
var provider = GetDataProvider(options, info, connectionInfo);
Expand Down Expand Up @@ -349,7 +349,7 @@ public static IDataContext CreateLinqToDBContext(this DbContext context,

DataConnection? dc = null;

transaction = transaction ?? context.Database.CurrentTransaction;
transaction ??= context.Database.CurrentTransaction;

var connectionInfo = GetConnectionInfo(info);
var provider = GetDataProvider(options, info, connectionInfo);
Expand Down Expand Up @@ -588,7 +588,9 @@ public static IQueryable<T> ToLinqToDB<T>(this IQueryable<T> query)
var context = Implementation.GetCurrentContext(query)
?? throw new LinqToDBForEFToolsException("Can not evaluate current context from query");

#pragma warning disable CA2000 // Dispose objects before losing scope
var dc = CreateLinqToDBContext(context);
#pragma warning restore CA2000 // Dispose objects before losing scope

return new LinqToDBForEFQueryProvider<T>(dc, query.Expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ object IEntityServiceInterceptor.EntityCreated(EntityCreatedEventData eventData,
body = Expression.Condition(checkExpression, invalidResult, body);
}

body = Expression.Block(new[] { variable }, assignExpr, body);
body = Expression.Block([variable], assignExpr, body);

var lambda =
Expression.Lambda<Func<IStateManager, object, Tuple<InternalEntityEntry?, bool>>>(body, stateManagerParam, objParam);
Expand Down
Loading

0 comments on commit 3c27d7f

Please sign in to comment.