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

Commit 227b93c

Browse files
authored
Merge pull request #151 from linq2db/version3
Release 3.11.1
2 parents c7f2c71 + 74cecbb commit 227b93c

File tree

9 files changed

+156
-164
lines changed

9 files changed

+156
-164
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.11.0</Version>
3+
<Version>3.11.1</Version>
44

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

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
using LinqToDB.Expressions;
99
using LinqToDB.Reflection;
1010
using Microsoft.EntityFrameworkCore;
11+
using Microsoft.EntityFrameworkCore.Infrastructure;
1112
using Microsoft.EntityFrameworkCore.Metadata;
1213
using Microsoft.EntityFrameworkCore.Metadata.Internal;
14+
using Microsoft.EntityFrameworkCore.Migrations;
1315
using Microsoft.EntityFrameworkCore.Query;
1416
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
1517
using Microsoft.EntityFrameworkCore.Storage;
@@ -22,7 +24,7 @@ namespace LinqToDB.EntityFrameworkCore
2224
using Common;
2325
using Internal;
2426
using SqlQuery;
25-
using SqlExpression = Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlExpression;
27+
using SqlExpression = SqlExpression;
2628

2729
/// <summary>
2830
/// LINQ To DB metadata reader for EF.Core model.
@@ -32,13 +34,19 @@ internal class EFCoreMetadataReader : IMetadataReader
3234
readonly IModel? _model;
3335
private readonly RelationalSqlTranslatingExpressionVisitorDependencies? _dependencies;
3436
private readonly IRelationalTypeMappingSource? _mappingSource;
35-
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?> _calculatedExtensions = new ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?>();
37+
private readonly IMigrationsAnnotationProvider? _annotationProvider;
38+
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?> _calculatedExtensions = new();
3639

37-
public EFCoreMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource)
40+
public EFCoreMetadataReader(
41+
IModel? model, IInfrastructure<IServiceProvider>? accessor)
3842
{
3943
_model = model;
40-
_dependencies = dependencies;
41-
_mappingSource = mappingSource;
44+
if (accessor != null)
45+
{
46+
_dependencies = accessor.GetService<RelationalSqlTranslatingExpressionVisitorDependencies>();
47+
_mappingSource = accessor.GetService<IRelationalTypeMappingSource>();
48+
_annotationProvider = accessor.GetService<IMigrationsAnnotationProvider>();
49+
}
4250
}
4351

4452
public T[] GetAttributes<T>(Type type, bool inherit = true) where T : Attribute
@@ -149,7 +157,13 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
149157
.FirstOrDefault(v => CompareProperty(v.p, memberInfo))?.index ?? 0;
150158
}
151159

152-
var isIdentity = prop.GetAnnotations()
160+
var annotations = prop.GetAnnotations();
161+
if (_annotationProvider != null)
162+
{
163+
annotations = annotations.Concat(_annotationProvider.For(prop));
164+
}
165+
166+
var isIdentity = annotations
153167
.Any(a =>
154168
{
155169
if (a.Name.EndsWith(":ValueGenerationStrategy"))

Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Linq.Expressions;
34

45
using Microsoft.EntityFrameworkCore;
56
using Microsoft.EntityFrameworkCore.Infrastructure;
67
using Microsoft.EntityFrameworkCore.Metadata;
7-
using Microsoft.EntityFrameworkCore.Query;
8-
using Microsoft.EntityFrameworkCore.Storage;
98
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
109
using Microsoft.Extensions.Logging;
1110

@@ -17,7 +16,7 @@ namespace LinqToDB.EntityFrameworkCore
1716
using Data;
1817

1918
/// <summary>
20-
/// Interface for EF.Core - LINQ To DB integration bridge.
19+
/// Interface for EF Core - LINQ To DB integration bridge.
2120
/// </summary>
2221
public interface ILinqToDBForEFTools
2322
{
@@ -27,76 +26,78 @@ public interface ILinqToDBForEFTools
2726
void ClearCaches();
2827

2928
/// <summary>
30-
/// Returns LINQ To DB provider, based on provider data from EF.Core.
29+
/// Returns LINQ To DB provider, based on provider data from EF Core.
3130
/// </summary>
32-
/// <param name="providerInfo">Provider information, extracted from EF.Core.</param>
31+
/// <param name="providerInfo">Provider information, extracted from EF Core.</param>
3332
/// <param name="connectionInfo">Database connection information.</param>
3433
/// <returns>LINQ TO DB provider instance.</returns>
3534
IDataProvider? GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo);
3635

3736
/// <summary>
38-
/// Creates metadata provider for specified EF.Core data model.
37+
/// Creates metadata provider for specified EF Core data model. Default implementation uses
38+
/// <see cref="EFCoreMetadataReader"/> metadata provider.
3939
/// </summary>
40-
/// <param name="model">EF.Core data model.</param>
41-
/// <param name="dependencies"></param>
42-
/// <param name="mappingSource"></param>
43-
/// <returns>LINQ To DB metadata provider for specified EF.Core model. Can return <c>null</c>.</returns>
44-
IMetadataReader? CreateMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource);
40+
/// <param name="model">EF Core data model.</param>
41+
/// <param name="accessor">EF Core service provider.</param>
42+
/// <returns>LINQ To DB metadata provider for specified EF Core model.</returns>
43+
IMetadataReader? CreateMetadataReader(
44+
IModel? model,
45+
IInfrastructure<IServiceProvider>? accessor);
4546

4647
/// <summary>
47-
/// Creates mapping schema using provided EF.Core data model and metadata provider.
48+
/// Creates mapping schema using provided EF Core data model and metadata provider.
4849
/// </summary>
49-
/// <param name="model">EF.Core data model.</param>
50+
/// <param name="model">EF Core data model.</param>
5051
/// <param name="metadataReader">Additional optional LINQ To DB database metadata provider.</param>
5152
/// <param name="convertorSelector">EF Core registry for type conversion.</param>
52-
/// <returns>Mapping schema for provided EF.Core model.</returns>
53+
/// <returns>Mapping schema for provided EF Core model.</returns>
5354
MappingSchema CreateMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector);
5455

5556
/// <summary>
56-
/// Returns mapping schema using provided EF.Core data model and metadata provider.
57+
/// Returns mapping schema using provided EF Core data model and metadata provider.
5758
/// </summary>
58-
/// <param name="model">EF.Core data model.</param>
59+
/// <param name="model">EF Core data model.</param>
5960
/// <param name="metadataReader">Additional optional LINQ To DB database metadata provider.</param>
6061
/// <param name="convertorSelector">EF Core registry for type conversion.</param>
61-
/// <returns>Mapping schema for provided EF.Core model.</returns>
62+
/// <returns>Mapping schema for provided EF Core model.</returns>
6263
MappingSchema GetMappingSchema(IModel model, IMetadataReader? metadataReader, IValueConverterSelector? convertorSelector);
6364

6465
/// <summary>
65-
/// Returns EF.Core <see cref="IDbContextOptions"/> for specific <see cref="DbContext"/> instance.
66+
/// Returns EF Core <see cref="IDbContextOptions"/> for specific <see cref="DbContext"/> instance.
6667
/// </summary>
67-
/// <param name="context">EF.Core <see cref="DbContext"/> instance.</param>
68+
/// <param name="context">EF Core <see cref="DbContext"/> instance.</param>
6869
/// <returns><see cref="IDbContextOptions"/> instance.</returns>
6970
IDbContextOptions? GetContextOptions(DbContext? context);
7071

7172
/// <summary>
72-
/// Transforms EF.Core expression tree to LINQ To DB expression.
73+
/// Transforms EF Core expression tree to LINQ To DB expression.
7374
/// </summary>
74-
/// <param name="expression">EF.Core expression tree.</param>
75+
/// <param name="expression">EF Core expression tree.</param>
7576
/// <param name="dc">LINQ To DB <see cref="IDataContext"/> instance.</param>
7677
/// <param name="ctx">Optional DbContext instance.</param>
77-
/// <param name="model">EF.Core data model instance.</param>
78+
/// <param name="model">EF Core data model instance.</param>
7879
/// <returns>Transformed expression.</returns>
7980
Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model);
8081

8182
/// <summary>
8283
/// Extracts <see cref="DbContext"/> instance from <see cref="IQueryable"/> object.
8384
/// </summary>
84-
/// <param name="query">EF.Core query.</param>
85+
/// <param name="query">EF Core query.</param>
8586
/// <returns>Current <see cref="DbContext"/> instance.</returns>
8687
DbContext? GetCurrentContext(IQueryable query);
8788

8889
/// <summary>
89-
/// Extracts EF.Core connection information object from <see cref="IDbContextOptions"/>.
90+
/// Extracts EF Core connection information object from <see cref="IDbContextOptions"/>.
9091
/// </summary>
9192
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
92-
/// <returns>EF.Core connection data.</returns>
93+
/// <returns>EF Core connection data.</returns>
9394
EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options);
9495

9596
/// <summary>
96-
/// Extracts EF.Core data model instance from <see cref="IDbContextOptions"/>.
97+
/// Extracts EF Core data model instance from <see cref="IDbContextOptions"/>.
9798
/// </summary>
9899
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
99-
/// <returns>EF.Core data model instance.</returns>
100+
/// <returns>EF Core data model instance.</returns>
100101
IModel? ExtractModel(IDbContextOptions? options);
101102

102103
/// <summary>

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public TResult Execute<TResult>(Expression expression)
8383
return QueryProvider.Execute<TResult>(expression);
8484
}
8585

86-
private static MethodInfo _executeAsyncMethodInfo =
86+
private static readonly MethodInfo _executeAsyncMethodInfo =
8787
MemberHelper.MethodOf((IQueryProviderAsync p) => p.ExecuteAsync<int>(null!, default)).GetGenericMethodDefinition();
8888

8989
/// <summary>

0 commit comments

Comments
 (0)