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

Commit cc95fae

Browse files
authored
Merge pull request #235 from linq2db/version6
Version 6.8.0
2 parents 9fc82fd + 6963a68 commit cc95fae

File tree

16 files changed

+88
-164
lines changed

16 files changed

+88
-164
lines changed

Build/linq2db.Default.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>6.7.1</Version>
3+
<Version>6.8.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-2021 linq2db.net</Copyright>
8+
<Copyright>2002-2022 linq2db.net</Copyright>
99
<RepositoryUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</RepositoryUrl>
1010
<RepositoryType>git</RepositoryType>
1111

Directory.Packages.props

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
4-
<PackageVersion Include="NUnit3TestAdapter" Version="4.0.0" />
5-
<PackageVersion Include="NUnit" Version="3.13.2" />
6-
<PackageVersion Include="FluentAssertions" Version="6.2.0" />
3+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
4+
<PackageVersion Include="NUnit3TestAdapter" Version="4.2.1" />
5+
<PackageVersion Include="NUnit" Version="3.13.3" />
6+
<PackageVersion Include="FluentAssertions" Version="6.6.0" />
77

8-
<PackageVersion Include="linq2db" Version="3.7.0" />
9-
<PackageVersion Include="linq2db.Tools" Version="3.7.0" />
8+
<PackageVersion Include="linq2db" Version="4.0.1" />
9+
<PackageVersion Include="linq2db.Tools" Version="4.0.1" />
1010

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

13-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
14-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.0" />
13+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
14+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.5" />
1515

1616
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
1717
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1818

19-
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
20-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
19+
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
20+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.5" />
22+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
2323
</ItemGroup>
2424
</Project>

NuGet.config

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
55
<add key="linq2db" value="https://pkgs.dev.azure.com/linq2db/linq2db/_packaging/linq2db/nuget/v3/index.json" />
66
</packageSources>
7-
</configuration>
7+
<packageSourceMapping>
8+
<packageSource key="NuGet">
9+
<package pattern="*" />
10+
</packageSource>
11+
</packageSourceMapping>
12+
</configuration>

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<license type="file">MIT-LICENSE.txt</license>
1616
<dependencies>
1717
<group targetFramework="net6.0">
18-
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.0" />
19-
<dependency id="linq2db" version="3.7.0" />
18+
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.5" />
19+
<dependency id="linq2db" version="4.0.1" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Concurrent;
43
using System.Collections.Generic;
54
using System.Data;
@@ -20,11 +19,11 @@
2019

2120
namespace LinqToDB.EntityFrameworkCore
2221
{
23-
using Mapping;
24-
using Metadata;
25-
using Extensions;
2622
using Common;
23+
using Extensions;
2724
using Internal;
25+
using Mapping;
26+
using Metadata;
2827
using SqlQuery;
2928
using SqlExpression = SqlExpression;
3029

@@ -321,8 +320,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
321320
{
322321
ThisKey = thisKey,
323322
OtherKey = otherKey,
324-
CanBeNull = !fk.IsRequiredDependent,
325-
IsBackReference = false
323+
CanBeNull = !fk.IsRequiredDependent
326324
});
327325
}
328326
else
@@ -333,8 +331,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
333331
{
334332
ThisKey = thisKey,
335333
OtherKey = otherKey,
336-
CanBeNull = !fk.IsRequired,
337-
IsBackReference = true
334+
CanBeNull = !fk.IsRequired
338335
});
339336
}
340337
}
@@ -578,7 +575,7 @@ string PrepareExpressionText(Expression? expr)
578575
if (expr is SqlFunctionExpression sqlFunction)
579576
{
580577
var text = sqlFunction.Name;
581-
if (!sqlFunction.Schema.IsNullOrEmpty())
578+
if (!string.IsNullOrEmpty(sqlFunction.Schema))
582579
text = sqlFunction.Schema + "." + sqlFunction.Name;
583580

584581
if (!sqlFunction.IsNiladic)

Source/LinqToDB.EntityFrameworkCore/Internal/EFCoreExpressionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public EFCoreExpressionAttribute(string expression) : base(expression)
2020
{
2121
}
2222

23-
/// <inheritdoc />
23+
/// <inheritdoc/>
2424
public override ISqlExpression? GetExpression<TContext>(
2525
TContext context,
2626
IDataContext dataContext,

Source/LinqToDB.EntityFrameworkCore/LinqToDBExtensionsAdapter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,30 @@ public Task<long> LongCountAsync<TSource>(
187187
=> EntityFrameworkQueryableExtensions.LongCountAsync(source, predicate, token);
188188

189189
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MinAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
190-
public Task<TSource> MinAsync<TSource>(
190+
public Task<TSource?> MinAsync<TSource>(
191191
IQueryable<TSource> source,
192192
CancellationToken token)
193-
=> EntityFrameworkQueryableExtensions.MinAsync(source, token);
193+
=> EntityFrameworkQueryableExtensions.MinAsync(source, token)!;
194194

195195
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MinAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
196-
public Task<TResult> MinAsync<TSource,TResult>(
196+
public Task<TResult?> MinAsync<TSource,TResult>(
197197
IQueryable<TSource> source,
198198
Expression<Func<TSource,TResult>> selector,
199199
CancellationToken token)
200-
=> EntityFrameworkQueryableExtensions.MinAsync(source, selector, token);
200+
=> EntityFrameworkQueryableExtensions.MinAsync(source, selector, token)!;
201201

202202
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MaxAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
203-
public Task<TSource> MaxAsync<TSource>(
203+
public Task<TSource?> MaxAsync<TSource>(
204204
IQueryable<TSource> source,
205205
CancellationToken token)
206-
=> EntityFrameworkQueryableExtensions.MaxAsync(source, token);
206+
=> EntityFrameworkQueryableExtensions.MaxAsync(source, token)!;
207207

208208
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MaxAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
209-
public Task<TResult> MaxAsync<TSource,TResult>(
209+
public Task<TResult?> MaxAsync<TSource,TResult>(
210210
IQueryable<TSource> source,
211211
Expression<Func<TSource,TResult>> selector,
212212
CancellationToken token)
213-
=> EntityFrameworkQueryableExtensions.MaxAsync(source, selector, token);
213+
=> EntityFrameworkQueryableExtensions.MaxAsync(source, selector, token)!;
214214

215215
#region SumAsync
216216

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFExtensions.Async.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,26 @@ public static Task<long> LongCountAsyncLinqToDB<TSource>(
168168
=> AsyncExtensions.LongCountAsync(source.ToLinqToDB(), predicate, token);
169169

170170
/// <inheritdoc cref="AsyncExtensions.MinAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
171-
public static Task<TSource> MinAsyncLinqToDB<TSource>(
171+
public static Task<TSource?> MinAsyncLinqToDB<TSource>(
172172
this IQueryable<TSource> source,
173173
CancellationToken token = default)
174174
=> AsyncExtensions.MinAsync(source.ToLinqToDB(), token);
175175

176176
/// <inheritdoc cref="AsyncExtensions.MinAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
177-
public static Task<TResult> MinAsyncLinqToDB<TSource,TResult>(
177+
public static Task<TResult?> MinAsyncLinqToDB<TSource,TResult>(
178178
this IQueryable<TSource> source,
179179
Expression<Func<TSource,TResult>> selector,
180180
CancellationToken token = default)
181181
=> AsyncExtensions.MinAsync(source.ToLinqToDB(), selector, token);
182182

183183
/// <inheritdoc cref="AsyncExtensions.MaxAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
184-
public static Task<TSource> MaxAsyncLinqToDB<TSource>(
184+
public static Task<TSource?> MaxAsyncLinqToDB<TSource>(
185185
this IQueryable<TSource> source,
186186
CancellationToken token = default)
187187
=> AsyncExtensions.MaxAsync(source.ToLinqToDB(), token);
188188

189189
/// <inheritdoc cref="AsyncExtensions.MaxAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
190-
public static Task<TResult> MaxAsyncLinqToDB<TSource,TResult>(
190+
public static Task<TResult?> MaxAsyncLinqToDB<TSource,TResult>(
191191
this IQueryable<TSource> source,
192192
Expression<Func<TSource,TResult>> selector,
193193
CancellationToken token = default)

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.Mapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void InitializeSqlServerMapping()
5959
var dateDiffStr = "DateDiff";
6060
var dateDiffMethods = sqlServerMethods.Where(m => m.Name.StartsWith(dateDiffStr)).ToArray();
6161

62-
var dateDiffMethod = MemberHelper.MethodOf(() => Sql.DateDiff(Sql.DateParts.Day, null, null));
62+
var dateDiffMethod = MemberHelper.MethodOf(() => Sql.DateDiff(Sql.DateParts.Day, (DateTime?)null, null));
6363

6464
foreach (var method in dateDiffMethods)
6565
{

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ namespace LinqToDB.EntityFrameworkCore
1919
using DataProvider;
2020
using Linq;
2121
using Expressions;
22+
using LinqToDB.Interceptors;
23+
using System.Data.Common;
2224

2325
/// <summary>
2426
/// linq2db EF.Core data connection.
2527
/// </summary>
26-
public class LinqToDBForEFToolsDataConnection : DataConnection, IExpressionPreprocessor
28+
public class LinqToDBForEFToolsDataConnection : DataConnection, IExpressionPreprocessor, IEntityServiceInterceptor
2729
{
2830
readonly IModel? _model;
2931
readonly Func<Expression, IDataContext, DbContext?, IModel?, Expression>? _transformFunc;
@@ -67,7 +69,7 @@ public LinqToDBForEFToolsDataConnection(
6769
_transformFunc = transformFunc;
6870
CopyDatabaseProperties();
6971
if (LinqToDBForEFTools.EnableChangeTracker)
70-
OnEntityCreated += OnEntityCreatedHandler;
72+
AddInterceptor(this);
7173
}
7274

7375
/// <summary>
@@ -80,18 +82,18 @@ public LinqToDBForEFToolsDataConnection(
8082
/// <param name="transformFunc">Expression converter.</param>
8183
public LinqToDBForEFToolsDataConnection(
8284
DbContext? context,
83-
[NotNull] IDataProvider dataProvider,
84-
[NotNull] IDbTransaction transaction,
85-
IModel? model,
86-
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc
87-
) : base(dataProvider, transaction)
85+
[NotNull] IDataProvider dataProvider,
86+
[NotNull] DbTransaction transaction,
87+
IModel? model,
88+
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc)
89+
: base(dataProvider, transaction)
8890
{
8991
Context = context;
9092
_model = model;
9193
_transformFunc = transformFunc;
9294
CopyDatabaseProperties();
9395
if (LinqToDBForEFTools.EnableChangeTracker)
94-
OnEntityCreated += OnEntityCreatedHandler;
96+
AddInterceptor(this);
9597
}
9698

9799
/// <summary>
@@ -105,7 +107,7 @@ public LinqToDBForEFToolsDataConnection(
105107
public LinqToDBForEFToolsDataConnection(
106108
DbContext? context,
107109
[NotNull] IDataProvider dataProvider,
108-
[NotNull] IDbConnection connection,
110+
[NotNull] DbConnection connection,
109111
IModel? model,
110112
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc) : base(dataProvider, connection)
111113
{
@@ -114,7 +116,7 @@ public LinqToDBForEFToolsDataConnection(
114116
_transformFunc = transformFunc;
115117
CopyDatabaseProperties();
116118
if (LinqToDBForEFTools.EnableChangeTracker)
117-
OnEntityCreated += OnEntityCreatedHandler;
119+
AddInterceptor(this);
118120
}
119121

120122
/// <summary>
@@ -157,7 +159,7 @@ public override bool Equals(object? obj)
157159
return true;
158160
}
159161

160-
if (obj.GetType() != this.GetType())
162+
if (obj.GetType() != GetType())
161163
{
162164
return false;
163165
}
@@ -174,34 +176,34 @@ public override int GetHashCode()
174176
}
175177
}
176178

177-
private void OnEntityCreatedHandler(EntityCreatedEventArgs args)
179+
object IEntityServiceInterceptor.EntityCreated(EntityCreatedEventData eventData, object entity)
178180
{
179181
// Do not allow to store in ChangeTracker temporary tables
180-
if ((args.TableOptions & TableOptions.IsTemporaryOptionSet) != 0)
181-
return;
182+
if ((eventData.TableOptions & TableOptions.IsTemporaryOptionSet) != 0)
183+
return entity;
182184

183185
// Do not allow to store in ChangeTracker tables from different server
184-
if (args.ServerName != null)
185-
return;
186+
if (eventData.ServerName != null)
187+
return entity;
186188

187189
if (!LinqToDBForEFTools.EnableChangeTracker
188190
|| !Tracking
189191
|| Context!.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.NoTracking)
190-
return;
192+
return entity;
191193

192-
var type = args.Entity.GetType();
194+
var type = entity.GetType();
193195
if (_lastType != type)
194196
{
195197
_lastType = type;
196198
_lastEntityType = Context.Model.FindEntityType(type);
197199
}
198200

199201
if (_lastEntityType == null)
200-
return;
202+
return entity;
201203

202204
// Do not allow to store in ChangeTracker tables that has different name
203-
if (args.TableName != _lastEntityType.GetTableName())
204-
return;
205+
if (eventData.TableName != _lastEntityType.GetTableName())
206+
return entity;
205207

206208
if (_stateManager == null)
207209
_stateManager = Context.GetService<IStateManager>();
@@ -220,16 +222,16 @@ private void OnEntityCreatedHandler(EntityCreatedEventArgs args)
220222
});
221223

222224
if (retrievalFunc == null)
223-
return;
225+
return entity;
224226

225-
entry = retrievalFunc(_stateManager, args.Entity);
227+
entry = retrievalFunc(_stateManager, entity);
226228

227229
if (entry == null)
228230
{
229-
entry = _stateManager.StartTrackingFromQuery(_lastEntityType, args.Entity, ValueBuffer.Empty);
231+
entry = _stateManager.StartTrackingFromQuery(_lastEntityType, entity, ValueBuffer.Empty);
230232
}
231233

232-
args.Entity = entry.Entity;
234+
return entry.Entity;
233235
}
234236

235237
private Func<IStateManager, object, InternalEntityEntry?>? CreateEntityRetrievalFunc(IEntityType entityType)

0 commit comments

Comments
 (0)