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

Commit 7411783

Browse files
authored
Merge pull request #175 from linq2db/version3
Release 3.14.0
2 parents 8bc069a + 9a1563d commit 7411783

File tree

14 files changed

+239
-40
lines changed

14 files changed

+239
-40
lines changed

Build/linq2db.Default.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.13.0</Version>
3+
<Version>3.14.0</Version>
44

55
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
66
<Product>Linq to DB</Product>

Directory.Packages.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<PackageVersion Include="NUnit" Version="3.13.2" />
66
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
77

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

1111
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
1212
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
@@ -15,8 +15,8 @@
1515
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
1616
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.11" />
1717

18-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="3.1.11" />
19-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="3.1.11" />
18+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
19+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
2020

2121
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
2222
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework=".NETStandard2.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.11" />
19-
<dependency id="linq2db" version="3.4.3" />
19+
<dependency id="linq2db" version="3.4.4" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ public T[] GetAttributes<T>(Type type, bool inherit = true) where T : Attribute
108108
if (tableAttribute != null)
109109
return new[] { (T)(Attribute)new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema } };
110110
}
111+
else if (_model != null && typeof(T) == typeof(InheritanceMappingAttribute))
112+
{
113+
if (et != null)
114+
{
115+
var derivedEntities = _model.GetEntityTypes().Where(e => e.BaseType == et && e.GetDiscriminatorValue() != null).ToList();
116+
117+
return
118+
derivedEntities.Select(e =>
119+
(T)(Attribute)new InheritanceMappingAttribute
120+
{
121+
Type = e.ClrType,
122+
Code = e.GetDiscriminatorValue()
123+
}
124+
)
125+
.ToArray();
126+
}
127+
128+
}
111129

112130
return Array.Empty<T>();
113131
}
@@ -186,11 +204,13 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
186204

187205
if (prop != null)
188206
{
207+
var discriminator = et.GetDiscriminatorProperty();
208+
189209
var isPrimaryKey = prop.IsPrimaryKey();
190210
var primaryKeyOrder = 0;
191211
if (isPrimaryKey)
192212
{
193-
var pk = prop.FindContainingPrimaryKey();
213+
var pk = prop.FindContainingPrimaryKey()!;
194214
primaryKeyOrder = pk.Properties.Select((p, i) => new { p, index = i })
195215
.FirstOrDefault(v => CompareProperty(v.p, memberInfo))?.index ?? 0;
196216
}
@@ -248,6 +268,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
248268
IsPrimaryKey = isPrimaryKey,
249269
PrimaryKeyOrder = primaryKeyOrder,
250270
IsIdentity = isIdentity,
271+
IsDiscriminator = discriminator == prop
251272
}
252273
};
253274
}

Source/LinqToDB.EntityFrameworkCore/Internal/EFCoreExpressionAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public override ISqlExpression GetExpression(
3232
{
3333
var mc = (MethodCallExpression) expression;
3434
if (!mc.Method.IsStatic)
35-
knownExpressions.Add(mc.Object);
35+
knownExpressions.Add(mc.Object!);
3636
knownExpressions.AddRange(mc.Arguments);
3737
}
3838
else
3939
{
4040
var me = (MemberExpression) expression;
41-
knownExpressions.Add(me.Expression);
41+
knownExpressions.Add(me.Expression!);
4242
}
4343

4444
var pams = new List<ISqlExpression?>(knownExpressions.Select(_ => (ISqlExpression?) null));

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
6767
/// </summary>
6868
/// <param name="expression">Query expression.</param>
6969
/// <returns>Query result.</returns>
70-
public object Execute(Expression expression)
70+
public object? Execute(Expression expression)
7171
{
7272
return QueryProvider.Execute(expression);
7373
}
@@ -109,7 +109,7 @@ TResult IAsyncQueryProvider.ExecuteAsync<TResult>(Expression expression, Cancell
109109
{
110110
var item = typeof(TResult).GetGenericArguments()[0];
111111
var method = _executeAsyncMethodInfo.MakeGenericMethod(item);
112-
return (TResult) method.Invoke(QueryProvider, new object[] { expression, cancellationToken });
112+
return (TResult) method.Invoke(QueryProvider, new object[] { expression, cancellationToken })!;
113113
}
114114

115115
/// <summary>
@@ -160,14 +160,15 @@ IEnumerator IEnumerable.GetEnumerator()
160160
/// <returns>Query result as <see cref="IAsyncEnumerable{T}"/>.</returns>
161161
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken)
162162
{
163-
return QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
163+
return Task.Run(() => QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken),
164+
cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
164165
}
165166

166167
/// <summary>
167168
/// Returns generated SQL for specific LINQ query.
168169
/// </summary>
169170
/// <returns>Generated SQL.</returns>
170-
public override string ToString()
171+
public override string? ToString()
171172
{
172173
return QueryProvider.ToString();
173174
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFExtensions.Async.EF.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static Task<Dictionary<TKey, TSource>> ToDictionaryAsyncEF<TSource, TKey>
3939
this IQueryable<TSource> source,
4040
Func<TSource, TKey> keySelector,
4141
CancellationToken cancellationToken = default)
42+
where TKey: notnull
4243
=> EntityFrameworkQueryableExtensions.ToDictionaryAsync(source, keySelector, cancellationToken);
4344

4445
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.ToDictionaryAsync{TSource, TKey, TElement}(IQueryable{TSource}, Func{TSource, TKey}, Func{TSource, TElement}, CancellationToken)"/>
@@ -47,6 +48,7 @@ public static Task<Dictionary<TKey,TElement>> ToDictionaryAsyncEF<TSource,TKey,T
4748
Func<TSource,TKey> keySelector,
4849
Func<TSource,TElement> elementSelector,
4950
CancellationToken cancellationToken = default)
51+
where TKey : notnull
5052
=> EntityFrameworkQueryableExtensions.ToDictionaryAsync(source, keySelector, elementSelector, cancellationToken);
5153

5254
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.ToDictionaryAsync{TSource, TKey, TElement}(IQueryable{TSource}, Func{TSource, TKey}, Func{TSource, TElement}, IEqualityComparer{TKey}, CancellationToken)"/>
@@ -56,6 +58,7 @@ public static Task<Dictionary<TKey,TElement>> ToDictionaryAsyncEF<TSource,TKey,T
5658
Func<TSource,TElement> elementSelector,
5759
IEqualityComparer<TKey> comparer,
5860
CancellationToken cancellationToken = default)
61+
where TKey : notnull
5962
=> EntityFrameworkQueryableExtensions.ToDictionaryAsync(source, keySelector, elementSelector, comparer, cancellationToken);
6063

6164
/// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsDataConnection.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public class LinqToDBForEFToolsDataConnection : DataConnection, IExpressionPrepr
5656
/// <param name="model">EF.Core data model.</param>
5757
/// <param name="transformFunc">Expression converter.</param>
5858
public LinqToDBForEFToolsDataConnection(
59-
DbContext? context,
60-
IDataProvider dataProvider,
61-
string connectionString,
62-
IModel? model,
59+
DbContext? context,
60+
[NotNull] IDataProvider dataProvider,
61+
[NotNull] string connectionString,
62+
IModel? model,
6363
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc) : base(dataProvider, connectionString)
6464
{
6565
Context = context;
@@ -79,10 +79,10 @@ public LinqToDBForEFToolsDataConnection(
7979
/// <param name="model">EF.Core data model.</param>
8080
/// <param name="transformFunc">Expression converter.</param>
8181
public LinqToDBForEFToolsDataConnection(
82-
DbContext? context,
83-
IDataProvider dataProvider,
84-
IDbTransaction transaction,
85-
IModel? model,
82+
DbContext? context,
83+
[NotNull] IDataProvider dataProvider,
84+
[NotNull] IDbTransaction transaction,
85+
IModel? model,
8686
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc
8787
) : base(dataProvider, transaction)
8888
{
@@ -103,10 +103,10 @@ public LinqToDBForEFToolsDataConnection(
103103
/// <param name="model">EF.Core data model.</param>
104104
/// <param name="transformFunc">Expression converter.</param>
105105
public LinqToDBForEFToolsDataConnection(
106-
DbContext? context,
107-
IDataProvider dataProvider,
108-
IDbConnection connection,
109-
IModel? model,
106+
DbContext? context,
107+
[NotNull] IDataProvider dataProvider,
108+
[NotNull] IDbConnection connection,
109+
IModel? model,
110110
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc) : base(dataProvider, connection)
111111
{
112112
Context = context;

Tests/LinqToDB.EntityFrameworkCore.BaseTests/ForMappingTestsBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public virtual void TestIdentityMapping()
2020
using var connection = context.CreateLinqToDbConnection();
2121

2222
var ed = connection.MappingSchema.GetEntityDescriptor(typeof(WithIdentity));
23-
var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single();
23+
var pk = ed.Columns.Single(c => c.IsPrimaryKey);
2424

2525
pk.IsIdentity.Should().BeTrue();
2626
}
@@ -32,7 +32,7 @@ public virtual void TestNoIdentityMapping()
3232
using var connection = context.CreateLinqToDbConnection();
3333

3434
var ed = connection.MappingSchema.GetEntityDescriptor(typeof(NoIdentity));
35-
var pk = ed.Columns.Where(c => c.IsPrimaryKey).Single();
35+
var pk = ed.Columns.Single(c => c.IsPrimaryKey);
3636

3737
pk.IsIdentity.Should().BeFalse();
3838
}

Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/TestLogger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
6060

6161
public virtual void WriteMessage(LogLevel logLevel, string logName, int eventId, string message, Exception exception)
6262
{
63-
var format = Options!.Format;
64-
Debug.Assert(format >= ConsoleLoggerFormat.Default && format <= ConsoleLoggerFormat.Systemd);
63+
var format = Options!.FormatterName;
64+
Debug.Assert(format is ConsoleFormatterNames.Simple or ConsoleFormatterNames.Systemd);
6565

6666
var logBuilder = _logBuilder;
6767
_logBuilder = null;
@@ -72,11 +72,11 @@ public virtual void WriteMessage(LogLevel logLevel, string logName, int eventId,
7272
}
7373

7474
LogMessageEntry entry;
75-
if (format == ConsoleLoggerFormat.Default)
75+
if (format == ConsoleFormatterNames.Simple)
7676
{
7777
entry = CreateDefaultLogMessage(logBuilder, logLevel, logName, eventId, message, exception);
7878
}
79-
else if (format == ConsoleLoggerFormat.Systemd)
79+
else if (format == ConsoleFormatterNames.Systemd)
8080
{
8181
entry = CreateSystemdLogMessage(logBuilder, logLevel, logName, eventId, message, exception);
8282
}

0 commit comments

Comments
 (0)