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

Commit c722e26

Browse files
MaceWindusdanyliv
authored andcommitted
updates + v4 migration
1 parent 0c3a1d6 commit c722e26

10 files changed

+88
-133
lines changed

Directory.Packages.props

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
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="5.10.3" />
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.0-rc.2" />
9+
<PackageVersion Include="linq2db.Tools" Version="4.0.0-rc.2" />
1010

1111
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
12-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
12+
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
1313

1414

15-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.6" />
16-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.6" />
15+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.25" />
16+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.25" />
1717

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

21-
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
22-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
23-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.15" />
24-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.10" />
21+
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.7" />
22+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.18" />
23+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.25" />
24+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.25" />
2525
</ItemGroup>
2626
</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=".NETStandard2.0">
18-
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.6" />
19-
<dependency id="linq2db" version="3.7.0" />
18+
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.25" />
19+
<dependency id="linq2db" version="4.0.0" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
317317
{
318318
ThisKey = thisKey,
319319
OtherKey = otherKey,
320-
CanBeNull = canBeNull,
321-
IsBackReference = false
320+
CanBeNull = canBeNull
322321
});
323322
}
324323
else
@@ -329,8 +328,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
329328
{
330329
ThisKey = thisKey,
331330
OtherKey = otherKey,
332-
CanBeNull = !fk.IsRequired,
333-
IsBackReference = true
331+
CanBeNull = !fk.IsRequired
334332
});
335333
}
336334
}
@@ -446,7 +444,7 @@ public override bool Equals(object obj)
446444
{
447445
if (ReferenceEquals(null, obj)) return false;
448446
if (ReferenceEquals(this, obj)) return true;
449-
if (obj.GetType() != this.GetType()) return false;
447+
if (obj.GetType() != GetType()) return false;
450448
return Equals((SqlTransparentExpression) obj);
451449
}
452450

@@ -565,7 +563,7 @@ string PrepareExpressionText(Expression? expr)
565563
if (expr is SqlFunctionExpression sqlFunction)
566564
{
567565
var text = sqlFunction.Name;
568-
if (!sqlFunction.Schema.IsNullOrEmpty())
566+
if (!string.IsNullOrEmpty(sqlFunction.Schema))
569567
text = sqlFunction.Schema + "." + sqlFunction.Name;
570568

571569
if (!sqlFunction.IsNiladic)

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/LinqToDBForEFToolsDataConnection.cs

Lines changed: 25 additions & 23 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,9 +82,9 @@ 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,
85+
[NotNull] IDataProvider dataProvider,
86+
[NotNull] DbTransaction transaction,
87+
IModel? model,
8688
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc
8789
) : base(dataProvider, transaction)
8890
{
@@ -91,7 +93,7 @@ public LinqToDBForEFToolsDataConnection(
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)