Skip to content

Commit

Permalink
Merge pull request #151 from linq2db/version3
Browse files Browse the repository at this point in the history
Release 3.11.1
  • Loading branch information
sdanyliv authored Jun 10, 2021
2 parents c7f2c71 + 74cecbb commit 227b93c
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 164 deletions.
2 changes: 1 addition & 1 deletion Build/linq2db.Default.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.11.0</Version>
<Version>3.11.1</Version>

<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
<Product>Linq to DB</Product>
Expand Down
26 changes: 20 additions & 6 deletions Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using LinqToDB.Expressions;
using LinqToDB.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
Expand All @@ -22,7 +24,7 @@ namespace LinqToDB.EntityFrameworkCore
using Common;
using Internal;
using SqlQuery;
using SqlExpression = Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlExpression;
using SqlExpression = SqlExpression;

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

public EFCoreMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource)
public EFCoreMetadataReader(
IModel? model, IInfrastructure<IServiceProvider>? accessor)
{
_model = model;
_dependencies = dependencies;
_mappingSource = mappingSource;
if (accessor != null)
{
_dependencies = accessor.GetService<RelationalSqlTranslatingExpressionVisitorDependencies>();
_mappingSource = accessor.GetService<IRelationalTypeMappingSource>();
_annotationProvider = accessor.GetService<IMigrationsAnnotationProvider>();
}
}

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

var isIdentity = prop.GetAnnotations()
var annotations = prop.GetAnnotations();
if (_annotationProvider != null)
{
annotations = annotations.Concat(_annotationProvider.For(prop));
}

var isIdentity = annotations
.Any(a =>
{
if (a.Name.EndsWith(":ValueGenerationStrategy"))
Expand Down
57 changes: 29 additions & 28 deletions Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Linq;
using System;
using System.Linq;
using System.Linq.Expressions;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.Extensions.Logging;

Expand All @@ -17,7 +16,7 @@ namespace LinqToDB.EntityFrameworkCore
using Data;

/// <summary>
/// Interface for EF.Core - LINQ To DB integration bridge.
/// Interface for EF Core - LINQ To DB integration bridge.
/// </summary>
public interface ILinqToDBForEFTools
{
Expand All @@ -27,76 +26,78 @@ public interface ILinqToDBForEFTools
void ClearCaches();

/// <summary>
/// Returns LINQ To DB provider, based on provider data from EF.Core.
/// Returns LINQ To DB provider, based on provider data from EF Core.
/// </summary>
/// <param name="providerInfo">Provider information, extracted from EF.Core.</param>
/// <param name="providerInfo">Provider information, extracted from EF Core.</param>
/// <param name="connectionInfo">Database connection information.</param>
/// <returns>LINQ TO DB provider instance.</returns>
IDataProvider? GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo);

/// <summary>
/// Creates metadata provider for specified EF.Core data model.
/// Creates metadata provider for specified EF Core data model. Default implementation uses
/// <see cref="EFCoreMetadataReader"/> metadata provider.
/// </summary>
/// <param name="model">EF.Core data model.</param>
/// <param name="dependencies"></param>
/// <param name="mappingSource"></param>
/// <returns>LINQ To DB metadata provider for specified EF.Core model. Can return <c>null</c>.</returns>
IMetadataReader? CreateMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource);
/// <param name="model">EF Core data model.</param>
/// <param name="accessor">EF Core service provider.</param>
/// <returns>LINQ To DB metadata provider for specified EF Core model.</returns>
IMetadataReader? CreateMetadataReader(
IModel? model,
IInfrastructure<IServiceProvider>? accessor);

/// <summary>
/// Creates mapping schema using provided EF.Core data model and metadata provider.
/// Creates mapping schema using provided EF Core data model and metadata provider.
/// </summary>
/// <param name="model">EF.Core data model.</param>
/// <param name="model">EF Core data model.</param>
/// <param name="metadataReader">Additional optional LINQ To DB database metadata provider.</param>
/// <param name="convertorSelector">EF Core registry for type conversion.</param>
/// <returns>Mapping schema for provided EF.Core model.</returns>
/// <returns>Mapping schema for provided EF Core model.</returns>
MappingSchema CreateMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector);

/// <summary>
/// Returns mapping schema using provided EF.Core data model and metadata provider.
/// Returns mapping schema using provided EF Core data model and metadata provider.
/// </summary>
/// <param name="model">EF.Core data model.</param>
/// <param name="model">EF Core data model.</param>
/// <param name="metadataReader">Additional optional LINQ To DB database metadata provider.</param>
/// <param name="convertorSelector">EF Core registry for type conversion.</param>
/// <returns>Mapping schema for provided EF.Core model.</returns>
/// <returns>Mapping schema for provided EF Core model.</returns>
MappingSchema GetMappingSchema(IModel model, IMetadataReader? metadataReader, IValueConverterSelector? convertorSelector);

/// <summary>
/// Returns EF.Core <see cref="IDbContextOptions"/> for specific <see cref="DbContext"/> instance.
/// Returns EF Core <see cref="IDbContextOptions"/> for specific <see cref="DbContext"/> instance.
/// </summary>
/// <param name="context">EF.Core <see cref="DbContext"/> instance.</param>
/// <param name="context">EF Core <see cref="DbContext"/> instance.</param>
/// <returns><see cref="IDbContextOptions"/> instance.</returns>
IDbContextOptions? GetContextOptions(DbContext? context);

/// <summary>
/// Transforms EF.Core expression tree to LINQ To DB expression.
/// Transforms EF Core expression tree to LINQ To DB expression.
/// </summary>
/// <param name="expression">EF.Core expression tree.</param>
/// <param name="expression">EF Core expression tree.</param>
/// <param name="dc">LINQ To DB <see cref="IDataContext"/> instance.</param>
/// <param name="ctx">Optional DbContext instance.</param>
/// <param name="model">EF.Core data model instance.</param>
/// <param name="model">EF Core data model instance.</param>
/// <returns>Transformed expression.</returns>
Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model);

/// <summary>
/// Extracts <see cref="DbContext"/> instance from <see cref="IQueryable"/> object.
/// </summary>
/// <param name="query">EF.Core query.</param>
/// <param name="query">EF Core query.</param>
/// <returns>Current <see cref="DbContext"/> instance.</returns>
DbContext? GetCurrentContext(IQueryable query);

/// <summary>
/// Extracts EF.Core connection information object from <see cref="IDbContextOptions"/>.
/// Extracts EF Core connection information object from <see cref="IDbContextOptions"/>.
/// </summary>
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
/// <returns>EF.Core connection data.</returns>
/// <returns>EF Core connection data.</returns>
EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options);

/// <summary>
/// Extracts EF.Core data model instance from <see cref="IDbContextOptions"/>.
/// Extracts EF Core data model instance from <see cref="IDbContextOptions"/>.
/// </summary>
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
/// <returns>EF.Core data model instance.</returns>
/// <returns>EF Core data model instance.</returns>
IModel? ExtractModel(IDbContextOptions? options);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public TResult Execute<TResult>(Expression expression)
return QueryProvider.Execute<TResult>(expression);
}

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

/// <summary>
Expand Down
Loading

0 comments on commit 227b93c

Please sign in to comment.