diff --git a/.editorconfig b/.editorconfig index ef2198a..dbe83cc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -251,6 +251,7 @@ dotnet_diagnostic.IDE0079.severity = none # IDE0079: Remove unnecessary suppress dotnet_diagnostic.IDE0080.severity = none # IDE0080: Remove unnecessary suppression operator dotnet_diagnostic.IDE0081.severity = none # IDE0081: Remove ByVal dotnet_diagnostic.IDE0083.severity = none # IDE0083: Use pattern matching (not operator) +dotnet_diagnostic.IDE0130.severity = none # IDE0130: Namespace does not match folder structure dotnet_diagnostic.IDE1006.severity = none # IDE1006: Naming rule violation dotnet_diagnostic.CS1998.severity = error # CS1998: Async method lacks 'await' operators and will run synchronously diff --git a/Build/linq2db.Default.props b/Build/linq2db.Default.props index 18342b9..4f02df0 100644 --- a/Build/linq2db.Default.props +++ b/Build/linq2db.Default.props @@ -1,11 +1,11 @@  - 3.19.0 + 3.20.0 Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin Linq to DB linq2db.net - 2002-2021 linq2db.net + 2002-2022 linq2db.net https://github.com/linq2db/linq2db.EntityFrameworkCore git diff --git a/NuGet/linq2db.EntityFrameworkCore.nuspec b/NuGet/linq2db.EntityFrameworkCore.nuspec index b7892a5..7f5ea04 100644 --- a/NuGet/linq2db.EntityFrameworkCore.nuspec +++ b/NuGet/linq2db.EntityFrameworkCore.nuspec @@ -16,7 +16,7 @@ - + diff --git a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs index 166c65d..64fd267 100644 --- a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs +++ b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs @@ -511,7 +511,7 @@ public override int GetHashCode() var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource?.FindMapping(propInfo)); var newExpression = _dependencies.MemberTranslatorProvider.Translate(objExpr, propInfo, propInfo.GetMemberType()); - if (newExpression != null) + if (newExpression != null && newExpression != objExpr) { var parametersArray = new Expression[] { objExpr }; result = ConvertToExpressionAttribute(propInfo, newExpression, parametersArray); diff --git a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs index c32b5d4..08300fd 100644 --- a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs +++ b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -160,8 +161,17 @@ IEnumerator IEnumerable.GetEnumerator() /// Query result as . public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) { - return Task.Run(() => QueryProvider.ExecuteAsyncEnumerable(Expression, cancellationToken), - cancellationToken).Result.GetAsyncEnumerator(cancellationToken); + async IAsyncEnumerable EnumerateAsyncEnumerable([EnumeratorCancellation] CancellationToken ct) + { + var asyncEnumerable = await QueryProvider.ExecuteAsyncEnumerable(Expression, ct) + .ConfigureAwait(false); + await foreach (var item in asyncEnumerable.WithCancellation(ct).ConfigureAwait(false)) + { + yield return item; + } + } + + return EnumerateAsyncEnumerable(cancellationToken).GetAsyncEnumerator(cancellationToken); } /// diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs index 1078287..fed8bf5 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs @@ -85,8 +85,8 @@ public LinqToDBForEFToolsDataConnection( [NotNull] IDataProvider dataProvider, [NotNull] DbTransaction transaction, IModel? model, - Func? transformFunc - ) : base(dataProvider, transaction) + Func? transformFunc) + : base(dataProvider, transaction) { Context = context; _model = model; @@ -140,7 +140,7 @@ public TypeKey(IEntityType entityType, IModel? model) } public IEntityType EntityType { get; } - public IModel? Model { get; } + public IModel? Model { get; } protected bool Equals(TypeKey other) { @@ -187,7 +187,7 @@ object IEntityServiceInterceptor.EntityCreated(EntityCreatedEventData eventData, return entity; if (!LinqToDBForEFTools.EnableChangeTracker - || !Tracking + || !Tracking || Context!.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.NoTracking) return entity; @@ -243,9 +243,11 @@ object IEntityServiceInterceptor.EntityCreated(EntityCreatedEventData eventData, var assignExpr = Expression.Assign(variable, Expression.Convert(objParam, entityType.ClrType)); var key = entityType.GetKeys().FirstOrDefault(); + if (key == null) + return null; var arrayExpr = key.Properties.Where(p => p.PropertyInfo != null || p.FieldInfo != null).Select(p => - Expression.Convert(Expression.MakeMemberAccess(variable, p.PropertyInfo ?? (MemberInfo)p.FieldInfo), + Expression.Convert(Expression.MakeMemberAccess(variable, p.PropertyInfo ?? (MemberInfo)p.FieldInfo!), typeof(object))) .ToArray(); diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs index 19434c9..a456c42 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs @@ -1062,6 +1062,7 @@ public virtual EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options /// Logger instance. public virtual void LogConnectionTrace(TraceInfo info, ILogger logger) { +#pragma warning disable CA1848 // Use the LoggerMessage delegates var logLevel = info.TraceLevel switch { TraceLevel.Off => LogLevel.None, @@ -1072,7 +1073,6 @@ public virtual void LogConnectionTrace(TraceInfo info, ILogger logger) _ => LogLevel.Trace, }; -#pragma warning disable CA1848 // Use the LoggerMessage delegates using var _ = logger.BeginScope("TraceInfoStep: {TraceInfoStep}, IsAsync: {IsAsync}", info.TraceInfoStep, info.IsAsync); switch (info.TraceInfoStep) diff --git a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithXmin.cs b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithXmin.cs index b4896ee..cdb1865 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithXmin.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/EntityWithXmin.cs @@ -6,9 +6,8 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities public class EntityWithXmin { [Key] - public int Id { get; set; } - - public uint xmin { get; set; } + public int Id { get; set; } + public uint xmin { get; set; } public string Value { get; set; } = null!; } } diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/JsonConverTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/JsonConverTests.cs index e592cf7..2c5711e 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/JsonConverTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/JsonConverTests.cs @@ -27,7 +27,7 @@ public class EventScheduleItemBase { public int Id { get; set; } public virtual LocalizedString NameLocalized { get; set; } = null!; - public virtual string JsonColumn { get; set; } = null!; + public virtual string? JsonColumn { get; set; } } public enum CrashEnum : byte diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5427540..b2b22fa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,8 @@ variables: solution: 'linq2db.EFCore.sln' build_configuration: 'Release' - assemblyVersion: 3.19.0 - nugetVersion: 3.19.0 + assemblyVersion: 3.20.0 + nugetVersion: 3.20.0 artifact_nugets: 'nugets' # build on commits to important branches (master + release branches): diff --git a/linq2db.EFCore.sln b/linq2db.EFCore.sln index ed51014..2d7f125 100644 --- a/linq2db.EFCore.sln +++ b/linq2db.EFCore.sln @@ -1,14 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29324.140 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32505.173 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "linq2db.EntityFrameworkCore", "Source\LinqToDB.EntityFrameworkCore\linq2db.EntityFrameworkCore.csproj", "{29F45BE9-3B57-4162-A02A-59F05528A0E7}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{A3F30061-485E-4112-9675-3AE332BEED13}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore azure-pipelines.yml = azure-pipelines.yml Directory.Packages.props = Directory.Packages.props + global.json = global.json Build\linq2db.Default.props = Build\linq2db.Default.props Build\linq2db.snk = Build\linq2db.snk Build\linq2db.Tests.props = Build\linq2db.Tests.props