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

Commit b2fc60d

Browse files
authored
Merge pull request #236 from linq2db/master
Version 5.11.0
2 parents 33f389e + 365af8a commit b2fc60d

File tree

16 files changed

+135
-135
lines changed

16 files changed

+135
-135
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>5.10.0</Version>
3+
<Version>5.11.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="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.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="5.0.12" />
14-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
13+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.17" />
14+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.17" />
1515

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

19-
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.1" />
20-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.1" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
19+
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.4" />
20+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.17" />
22+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />
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=".NETStandard2.1">
18-
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.12" />
19-
<dependency id="linq2db" version="3.7.0" />
18+
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.17" />
19+
<dependency id="linq2db" version="4.0.1" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
263263
}
264264
}
265265

266+
var behaviour = prop.GetBeforeSaveBehavior();
267+
var skipOnInsert = prop.ValueGenerated.HasFlag(ValueGenerated.OnAdd);
268+
269+
if (skipOnInsert)
270+
{
271+
skipOnInsert = isIdentity || behaviour != PropertySaveBehavior.Save;
272+
}
273+
274+
var skipOnUpdate = behaviour != PropertySaveBehavior.Save ||
275+
prop.ValueGenerated.HasFlag(ValueGenerated.OnUpdate);
276+
266277
return new T[]
267278
{
268279
(T)(Attribute)new ColumnAttribute
@@ -275,7 +286,9 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
275286
IsPrimaryKey = isPrimaryKey,
276287
PrimaryKeyOrder = primaryKeyOrder,
277288
IsIdentity = isIdentity,
278-
IsDiscriminator = discriminator == prop
289+
IsDiscriminator = discriminator == prop,
290+
SkipOnInsert = skipOnInsert,
291+
SkipOnUpdate = skipOnUpdate
279292
}
280293
};
281294
}
@@ -306,10 +319,9 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
306319
var otherKey = string.Join(",", fk.Properties.Select(p => p.Name));
307320
associations.Add(new AssociationAttribute
308321
{
309-
ThisKey = thisKey,
310-
OtherKey = otherKey,
311-
CanBeNull = !fk.IsRequiredDependent,
312-
IsBackReference = false
322+
ThisKey = thisKey,
323+
OtherKey = otherKey,
324+
CanBeNull = !fk.IsRequiredDependent,
313325
});
314326
}
315327
else
@@ -318,10 +330,9 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
318330
var otherKey = string.Join(",", fk.PrincipalKey.Properties.Select(p => p.Name));
319331
associations.Add(new AssociationAttribute
320332
{
321-
ThisKey = thisKey,
322-
OtherKey = otherKey,
323-
CanBeNull = !fk.IsRequired,
324-
IsBackReference = true
333+
ThisKey = thisKey,
334+
OtherKey = otherKey,
335+
CanBeNull = !fk.IsRequired
325336
});
326337
}
327338
}
@@ -565,7 +576,7 @@ string PrepareExpressionText(Expression? expr)
565576
if (expr is SqlFunctionExpression sqlFunction)
566577
{
567578
var text = sqlFunction.Name;
568-
if (!sqlFunction.Schema.IsNullOrEmpty())
579+
if (!string.IsNullOrEmpty(sqlFunction.Schema))
569580
text = sqlFunction.Schema + "." + sqlFunction.Name;
570581

571582
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: 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,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>
@@ -138,7 +140,7 @@ public TypeKey(IEntityType entityType, IModel? model)
138140
}
139141

140142
public IEntityType EntityType { get; }
141-
public IModel? Model { get; }
143+
public IModel? Model { get; }
142144

143145
protected bool Equals(TypeKey other)
144146
{
@@ -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
188-
|| !Tracking
190+
|| !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)