diff --git a/Build/linq2db.Default.props b/Build/linq2db.Default.props index 6e4b65e..c6cdffc 100644 --- a/Build/linq2db.Default.props +++ b/Build/linq2db.Default.props @@ -1,6 +1,6 @@  - 3.11.0 + 3.11.1 Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin Linq to DB diff --git a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs index 84836eb..1af487f 100644 --- a/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs +++ b/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs @@ -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; @@ -22,7 +24,7 @@ namespace LinqToDB.EntityFrameworkCore using Common; using Internal; using SqlQuery; - using SqlExpression = Microsoft.EntityFrameworkCore.Query.SqlExpressions.SqlExpression; + using SqlExpression = SqlExpression; /// /// LINQ To DB metadata reader for EF.Core model. @@ -32,13 +34,19 @@ internal class EFCoreMetadataReader : IMetadataReader readonly IModel? _model; private readonly RelationalSqlTranslatingExpressionVisitorDependencies? _dependencies; private readonly IRelationalTypeMappingSource? _mappingSource; - private readonly ConcurrentDictionary _calculatedExtensions = new ConcurrentDictionary(); + private readonly IMigrationsAnnotationProvider? _annotationProvider; + private readonly ConcurrentDictionary _calculatedExtensions = new(); - public EFCoreMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource) + public EFCoreMetadataReader( + IModel? model, IInfrastructure? accessor) { _model = model; - _dependencies = dependencies; - _mappingSource = mappingSource; + if (accessor != null) + { + _dependencies = accessor.GetService(); + _mappingSource = accessor.GetService(); + _annotationProvider = accessor.GetService(); + } } public T[] GetAttributes(Type type, bool inherit = true) where T : Attribute @@ -149,7 +157,13 @@ public T[] GetAttributes(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")) diff --git a/Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs b/Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs index 9027aa5..9351b25 100644 --- a/Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs +++ b/Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs @@ -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; @@ -17,7 +16,7 @@ namespace LinqToDB.EntityFrameworkCore using Data; /// - /// Interface for EF.Core - LINQ To DB integration bridge. + /// Interface for EF Core - LINQ To DB integration bridge. /// public interface ILinqToDBForEFTools { @@ -27,76 +26,78 @@ public interface ILinqToDBForEFTools void ClearCaches(); /// - /// Returns LINQ To DB provider, based on provider data from EF.Core. + /// Returns LINQ To DB provider, based on provider data from EF Core. /// - /// Provider information, extracted from EF.Core. + /// Provider information, extracted from EF Core. /// Database connection information. /// LINQ TO DB provider instance. IDataProvider? GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo); /// - /// Creates metadata provider for specified EF.Core data model. + /// Creates metadata provider for specified EF Core data model. Default implementation uses + /// metadata provider. /// - /// EF.Core data model. - /// - /// - /// LINQ To DB metadata provider for specified EF.Core model. Can return null. - IMetadataReader? CreateMetadataReader(IModel? model, RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, IRelationalTypeMappingSource? mappingSource); + /// EF Core data model. + /// EF Core service provider. + /// LINQ To DB metadata provider for specified EF Core model. + IMetadataReader? CreateMetadataReader( + IModel? model, + IInfrastructure? accessor); /// - /// Creates mapping schema using provided EF.Core data model and metadata provider. + /// Creates mapping schema using provided EF Core data model and metadata provider. /// - /// EF.Core data model. + /// EF Core data model. /// Additional optional LINQ To DB database metadata provider. /// EF Core registry for type conversion. - /// Mapping schema for provided EF.Core model. + /// Mapping schema for provided EF Core model. MappingSchema CreateMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector); /// - /// Returns mapping schema using provided EF.Core data model and metadata provider. + /// Returns mapping schema using provided EF Core data model and metadata provider. /// - /// EF.Core data model. + /// EF Core data model. /// Additional optional LINQ To DB database metadata provider. /// EF Core registry for type conversion. - /// Mapping schema for provided EF.Core model. + /// Mapping schema for provided EF Core model. MappingSchema GetMappingSchema(IModel model, IMetadataReader? metadataReader, IValueConverterSelector? convertorSelector); /// - /// Returns EF.Core for specific instance. + /// Returns EF Core for specific instance. /// - /// EF.Core instance. + /// EF Core instance. /// instance. IDbContextOptions? GetContextOptions(DbContext? context); /// - /// Transforms EF.Core expression tree to LINQ To DB expression. + /// Transforms EF Core expression tree to LINQ To DB expression. /// - /// EF.Core expression tree. + /// EF Core expression tree. /// LINQ To DB instance. /// Optional DbContext instance. - /// EF.Core data model instance. + /// EF Core data model instance. /// Transformed expression. Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model); /// /// Extracts instance from object. /// - /// EF.Core query. + /// EF Core query. /// Current instance. DbContext? GetCurrentContext(IQueryable query); /// - /// Extracts EF.Core connection information object from . + /// Extracts EF Core connection information object from . /// /// instance. - /// EF.Core connection data. + /// EF Core connection data. EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options); /// - /// Extracts EF.Core data model instance from . + /// Extracts EF Core data model instance from . /// /// instance. - /// EF.Core data model instance. + /// EF Core data model instance. IModel? ExtractModel(IDbContextOptions? options); /// diff --git a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs index 2ebc69b..ef6d449 100644 --- a/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs +++ b/Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs @@ -83,7 +83,7 @@ public TResult Execute(Expression expression) return QueryProvider.Execute(expression); } - private static MethodInfo _executeAsyncMethodInfo = + private static readonly MethodInfo _executeAsyncMethodInfo = MemberHelper.MethodOf((IQueryProviderAsync p) => p.ExecuteAsync(null!, default)).GetGenericMethodDefinition(); /// diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs index 2057915..3485308 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs @@ -12,7 +12,6 @@ using Microsoft.Extensions.Logging; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace LinqToDB.EntityFrameworkCore @@ -28,15 +27,15 @@ namespace LinqToDB.EntityFrameworkCore using Internal; /// - /// EF.Core extensions to call LINQ To DB functionality. + /// EF Core extensions to call LINQ To DB functionality. /// [PublicAPI] public static partial class LinqToDBForEFTools { - static readonly Lazy _intialized = new Lazy(InitializeInternal); + static readonly Lazy _intialized = new(InitializeInternal); /// - /// Initializes integration of LINQ To DB with EF.Core. + /// Initializes integration of LINQ To DB with EF Core. /// public static void Initialize() { @@ -82,7 +81,7 @@ static bool InitializeInternal() static ILinqToDBForEFTools _implementation = null!; /// - /// Gets or sets EF.Core to LINQ To DB integration bridge implementation. + /// Gets or sets EF Core to LINQ To DB integration bridge implementation. /// public static ILinqToDBForEFTools Implementation { @@ -91,11 +90,11 @@ public static ILinqToDBForEFTools Implementation { _implementation = value ?? throw new ArgumentNullException(nameof(value)); _metadataReaders.Clear(); - _defaultMetadataReader = new Lazy(() => Implementation.CreateMetadataReader(null, null, null)); + _defaultMetadataReader = new Lazy(() => Implementation.CreateMetadataReader(null, null)); } } - static readonly ConcurrentDictionary _metadataReaders = new ConcurrentDictionary(); + static readonly ConcurrentDictionary _metadataReaders = new(); static Lazy _defaultMetadataReader = null!; @@ -116,28 +115,26 @@ static LinqToDBForEFTools() } /// - /// Creates or return existing metadata provider for provided EF.Core data model. If model is null, empty metadata + /// Creates or return existing metadata provider for provided EF Core data model. If model is null, empty metadata /// provider will be returned. /// - /// EF.Core data model instance. Could be null. - /// - /// + /// EF Core data model instance. Could be null. + /// EF Core service provider. /// LINQ To DB metadata provider. public static IMetadataReader? GetMetadataReader( IModel? model, - RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, - IRelationalTypeMappingSource? mappingSource) + IInfrastructure? accessor) { if (model == null) return _defaultMetadataReader.Value; - return _metadataReaders.GetOrAdd(model, m => Implementation.CreateMetadataReader(model, dependencies, mappingSource)); + return _metadataReaders.GetOrAdd(model, m => Implementation.CreateMetadataReader(model, accessor)); } /// - /// Returns EF.Core for specific instance. + /// Returns EF Core for specific instance. /// - /// EF.Core instance. + /// EF Core instance. /// instance. public static IDbContextOptions? GetContextOptions(DbContext context) { @@ -145,10 +142,10 @@ static LinqToDBForEFTools() } /// - /// Returns EF.Core database provider information for specific instance. + /// Returns EF Core database provider information for specific instance. /// - /// EF.Core instance. - /// EF.Core provider information. + /// EF Core instance. + /// EF Core provider information. public static EFProviderInfo GetEFProviderInfo(DbContext context) { var info = new EFProviderInfo @@ -162,10 +159,10 @@ public static EFProviderInfo GetEFProviderInfo(DbContext context) } /// - /// Returns EF.Core database provider information for specific instance. + /// Returns EF Core database provider information for specific instance. /// - /// EF.Core instance. - /// EF.Core provider information. + /// EF Core instance. + /// EF Core provider information. public static EFProviderInfo GetEFProviderInfo(DbConnection connection) { var info = new EFProviderInfo @@ -179,10 +176,10 @@ public static EFProviderInfo GetEFProviderInfo(DbConnection connection) } /// - /// Returns EF.Core database provider information for specific instance. + /// Returns EF Core database provider information for specific instance. /// - /// EF.Core instance. - /// EF.Core provider information. + /// EF Core instance. + /// EF Core provider information. public static EFProviderInfo GetEFProviderInfo(DbContextOptions options) { var info = new EFProviderInfo @@ -196,9 +193,9 @@ public static EFProviderInfo GetEFProviderInfo(DbContextOptions options) } /// - /// Returns LINQ To DB provider, based on provider data from EF.Core. + /// Returns LINQ To DB provider, based on provider data from EF Core. /// - /// EF.Core provider information. + /// EF Core provider information. /// Database connection information. /// LINQ TO DB provider instance. public static IDataProvider GetDataProvider(EFProviderInfo info, EFConnectionInfo connectionInfo) @@ -212,28 +209,27 @@ public static IDataProvider GetDataProvider(EFProviderInfo info, EFConnectionInf } /// - /// Creates mapping schema using provided EF.Core data model. + /// Creates mapping schema using provided EF Core data model. /// - /// EF.Core data model. - /// EF Core registry for type conversion. - /// - /// - /// Mapping schema for provided EF.Core model. - public static MappingSchema GetMappingSchema(IModel model, - IValueConverterSelector? convertorSelector, - RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, - IRelationalTypeMappingSource? mappingSource) + /// EF Core data model. + /// EF Core service provider. + /// Mapping schema for provided EF Core model. + public static MappingSchema GetMappingSchema( + IModel model, + IInfrastructure? accessor) { - return Implementation.GetMappingSchema(model, GetMetadataReader(model, dependencies, mappingSource), convertorSelector); + var converterSelector = accessor?.GetService(); + + return Implementation.GetMappingSchema(model, GetMetadataReader(model, accessor), converterSelector); } /// - /// Transforms EF.Core expression tree to LINQ To DB expression. + /// Transforms EF Core expression tree to LINQ To DB expression. /// - /// EF.Core expression tree. + /// EF Core expression tree. /// LINQ To DB instance. /// Optional DbContext instance. - /// EF.Core data model instance. + /// EF Core data model instance. /// Transformed expression. public static Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model) { @@ -242,9 +238,9 @@ public static Expression TransformExpression(Expression expression, IDataContext /// /// Creates LINQ To DB instance, attached to provided - /// EF.Core instance connection and transaction. + /// EF Core instance connection and transaction. /// - /// EF.Core instance. + /// EF Core instance. /// Optional transaction instance, to which created connection should be attached. /// If not specified, will use current transaction if it available. /// LINQ To DB instance. @@ -288,18 +284,15 @@ public static DataConnection CreateLinqToDbConnection(this DbContext context, EnableTracing(dc, logger); } - var dependencies = context.GetService(); - var mappingSource = context.GetService(); - var converters = context.GetService(); - var mappingSchema = GetMappingSchema(context.Model, converters, dependencies, mappingSource); + var mappingSchema = GetMappingSchema(context.Model, context); if (mappingSchema != null) dc.AddMappingSchema(mappingSchema); return dc; } - private static TraceSwitch _defaultTraceSwitch = - new TraceSwitch("DataConnection", "DataConnection trace switch", TraceLevel.Info.ToString()); + private static readonly TraceSwitch _defaultTraceSwitch = + new("DataConnection", "DataConnection trace switch", TraceLevel.Info.ToString()); static void EnableTracing(DataConnection dc, ILogger logger) { @@ -318,9 +311,9 @@ static void EnableTracing(DataConnection dc, ILogger logger) } /// - /// Creates linq2db data context for EF.Core database context. + /// Creates linq2db data context for EF Core database context. /// - /// EF.Core database context. + /// EF Core database context. /// Transaction instance. /// linq2db data context. public static IDataContext CreateLinqToDbContext(this DbContext context, @@ -334,13 +327,10 @@ public static IDataContext CreateLinqToDbContext(this DbContext context, transaction = transaction ?? context.Database.CurrentTransaction; - var connectionInfo = GetConnectionInfo(info); - var provider = GetDataProvider(info, connectionInfo); - var dependencies = context.GetService(); - var mappingSource = context.GetService(); - var converters = context.GetService(); - var mappingSchema = GetMappingSchema(context.Model, converters, dependencies, mappingSource); - var logger = CreateLogger(info.Options); + var connectionInfo = GetConnectionInfo(info); + var provider = GetDataProvider(info, connectionInfo); + var mappingSchema = GetMappingSchema(context.Model, context); + var logger = CreateLogger(info.Options); if (transaction != null) { @@ -387,9 +377,9 @@ public static IDataContext CreateLinqToDbContext(this DbContext context, /// /// Creates LINQ To DB instance that creates new database connection using connection - /// information from EF.Core instance. + /// information from EF Core instance. /// - /// EF.Core instance. + /// EF Core instance. /// LINQ To DB instance. public static DataConnection CreateLinq2DbConnectionDetached(this DbContext context) { @@ -407,10 +397,7 @@ public static DataConnection CreateLinq2DbConnectionDetached(this DbContext cont EnableTracing(dc, logger); } - var dependencies = context.GetService(); - var mappingSource = context.GetService(); - var converters = context.GetService(); - var mappingSchema = GetMappingSchema(context.Model, converters, dependencies, mappingSource); + var mappingSchema = GetMappingSchema(context.Model, context); if (mappingSchema != null) dc.AddMappingSchema(mappingSchema); @@ -418,12 +405,12 @@ public static DataConnection CreateLinq2DbConnectionDetached(this DbContext cont } - static readonly ConcurrentDictionary> _connectionStringExtractors = new ConcurrentDictionary>(); + static readonly ConcurrentDictionary> _connectionStringExtractors = new(); /// - /// Extracts database connection information from EF.Core provider data. + /// Extracts database connection information from EF Core provider data. /// - /// EF.Core database provider data. + /// EF Core database provider data. /// Database connection information. public static EFConnectionInfo GetConnectionInfo(EFProviderInfo info) { @@ -462,10 +449,10 @@ public static EFConnectionInfo GetConnectionInfo(EFProviderInfo info) } /// - /// Extracts EF.Core data model instance from . + /// Extracts EF Core data model instance from . /// /// instance. - /// EF.Core data model instance. + /// EF Core data model instance. public static IModel? GetModel(DbContextOptions? options) { if (options == null) @@ -475,9 +462,9 @@ public static EFConnectionInfo GetConnectionInfo(EFProviderInfo info) /// /// Creates new LINQ To DB instance using connectivity information from - /// EF.Core instance. + /// EF Core instance. /// - /// EF.Core instance. + /// EF Core instance. /// New LINQ To DB instance. public static DataConnection CreateLinqToDbConnection(this DbContextOptions options) { @@ -505,7 +492,7 @@ public static DataConnection CreateLinqToDbConnection(this DbContextOptions opti if (model != null) { - var mappingSchema = GetMappingSchema(model, null, null, null); + var mappingSchema = GetMappingSchema(model, null); if (mappingSchema != null) dc.AddMappingSchema(mappingSchema); } @@ -514,10 +501,10 @@ public static DataConnection CreateLinqToDbConnection(this DbContextOptions opti } /// - /// Converts EF.Core's query to LINQ To DB query and attach it to provided LINQ To DB . + /// Converts EF Core's query to LINQ To DB query and attach it to provided LINQ To DB . /// /// Entity type. - /// EF.Core query. + /// EF Core query. /// LINQ To DB to use with provided query. /// LINQ To DB query, attached to provided . public static IQueryable ToLinqToDB(this IQueryable query, IDataContext dc) @@ -530,11 +517,11 @@ public static IQueryable ToLinqToDB(this IQueryable query, IDataContext } /// - /// Converts EF.Core's query to LINQ To DB query and attach it to current EF.Core connection. + /// Converts EF Core's query to LINQ To DB query and attach it to current EF Core connection. /// /// Entity type. - /// EF.Core query. - /// LINQ To DB query, attached to current EF.Core connection. + /// EF Core query. + /// LINQ To DB query, attached to current EF Core connection. public static IQueryable ToLinqToDB(this IQueryable query) { if (query.Provider is IQueryProviderAsync) @@ -554,7 +541,7 @@ public static IQueryable ToLinqToDB(this IQueryable query) /// /// Extracts instance from object. /// - /// EF.Core query. + /// EF Core query. /// Current instance. public static DbContext? GetCurrentContext(IQueryable query) { diff --git a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs index 268d524..78a160c 100644 --- a/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs +++ b/Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs @@ -43,7 +43,7 @@ namespace LinqToDB.EntityFrameworkCore // ReSharper disable once ClassWithVirtualMembersNeverInherited.Global /// - /// Default EF.Core - LINQ To DB integration bridge implementation. + /// Default EF Core - LINQ To DB integration bridge implementation. /// [PublicAPI] public class LinqToDBForEFToolsImplDefault : ILinqToDBForEFTools @@ -104,10 +104,10 @@ public virtual void ClearCaches() } /// - /// Returns LINQ To DB provider, based on provider data from EF.Core. + /// Returns LINQ To DB provider, based on provider data from EF Core. /// Could be overriden if you have issues with default detection mechanisms. /// - /// Provider information, extracted from EF.Core. + /// Provider information, extracted from EF Core. /// /// LINQ TO DB provider instance. public virtual IDataProvider GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo) @@ -121,9 +121,9 @@ public virtual IDataProvider GetDataProvider(EFProviderInfo providerInfo, EFConn } /// - /// Converts EF.Core provider settings to linq2db provider settings. + /// Converts EF Core provider settings to linq2db provider settings. /// - /// EF.Core provider settings. + /// EF Core provider settings. /// linq2db provider settings. protected virtual LinqToDBProviderInfo GetLinqToDbProviderInfo(EFProviderInfo providerInfo) { @@ -151,9 +151,9 @@ protected virtual LinqToDBProviderInfo GetLinqToDbProviderInfo(EFProviderInfo pr /// /// Creates instance of linq2db database provider. /// - /// EF.Core provider settings. + /// EF Core provider settings. /// linq2db provider settings. - /// EF.Core connection settings. + /// EF Core connection settings. /// linq2db database provider. protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo providerInfo, LinqToDBProviderInfo provInfo, EFConnectionInfo connectionInfo) @@ -197,7 +197,7 @@ protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo provid /// /// Creates linq2db provider settings object from instance. /// - /// EF.Core database information object. + /// EF Core database information object. /// linq2db provider settings. protected virtual LinqToDBProviderInfo? GetLinqToDbProviderInfo(DatabaseFacade database) { @@ -285,7 +285,7 @@ protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo provid /// /// Creates linq2db provider settings object from instance. /// - /// EF.Core provider options. + /// EF Core provider options. /// linq2db provider settings. protected virtual LinqToDBProviderInfo? GetLinqToDbProviderInfo(RelationalOptionsExtension extensions) { @@ -387,28 +387,27 @@ protected virtual IDataProvider CreatePostgreSqlProvider(PostgreSQLVersion versi } /// - /// Creates metadata provider for specified EF.Core data model. Default implementation uses + /// Creates metadata provider for specified EF Core data model. Default implementation uses /// metadata provider. /// - /// EF.Core data model. - /// EF.Core service dependencies. - /// EF.Core mappings source. - /// LINQ To DB metadata provider for specified EF.Core model. - public virtual IMetadataReader CreateMetadataReader(IModel? model, - RelationalSqlTranslatingExpressionVisitorDependencies? dependencies, - IRelationalTypeMappingSource? mappingSource) + /// EF Core data model. + /// EF Core service provider. + /// LINQ To DB metadata provider for specified EF Core model. + public virtual IMetadataReader CreateMetadataReader(IModel? model, IInfrastructure? accessor) { - return new EFCoreMetadataReader(model, dependencies, mappingSource); + return new EFCoreMetadataReader(model, accessor); } /// - /// Creates mapping schema using provided EF.Core data model and metadata provider. + /// Creates mapping schema using provided EF Core data model and metadata provider. /// - /// EF.Core data model. + /// EF Core data model. /// Additional optional LINQ To DB database metadata provider. /// /// Mapping schema for provided EF.Core model. - public virtual MappingSchema CreateMappingSchema(IModel model, IMetadataReader? metadataReader, + public virtual MappingSchema CreateMappingSchema( + IModel model, + IMetadataReader? metadataReader, IValueConverterSelector? convertorSelector) { var schema = new MappingSchema(); @@ -421,10 +420,10 @@ public virtual MappingSchema CreateMappingSchema(IModel model, IMetadataReader? } /// - /// Import type conversions from EF.Core model into linq2db mapping schema. + /// Import type conversions from EF Core model into linq2db mapping schema. /// /// linq2db mapping schema. - /// EF.Core data mode. + /// EF Core data mode. /// Type filter. public virtual void DefineConvertors( MappingSchema mappingSchema, @@ -515,9 +514,9 @@ private static Expression WithConvertToObject(Expression valueExpression) : valueExpression; /// - /// Returns mapping schema using provided EF.Core data model and metadata provider. + /// Returns mapping schema using provided EF Core data model and metadata provider. /// - /// EF.Core data model. + /// EF Core data model. /// Additional optional LINQ To DB database metadata provider. /// /// Mapping schema for provided EF.Core model. @@ -543,9 +542,9 @@ public virtual MappingSchema GetMappingSchema( } /// - /// Returns EF.Core for specific instance. + /// Returns EF Core for specific instance. /// - /// EF.Core instance. + /// EF Core instance. /// instance. public virtual IDbContextOptions? GetContextOptions(DbContext? context) { @@ -753,14 +752,14 @@ static List CompactTree(List items, ExpressionType nodeT } /// - /// Transforms EF.Core expression tree to LINQ To DB expression. - /// Method replaces EF.Core instances with LINQ To DB + /// Transforms EF Core expression tree to LINQ To DB expression. + /// Method replaces EF Core instances with LINQ To DB /// calls. /// - /// EF.Core expression tree. + /// EF Core expression tree. /// LINQ To DB instance. /// Optional DbContext instance. - /// EF.Core data model instance. + /// EF Core data model instance. /// Transformed expression. public virtual Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model) { @@ -1018,9 +1017,9 @@ static bool IsEnumerableType(Type type, MappingSchema mappingSchema) /// /// Extracts instance from object. - /// Due to unavailability of integration API in EF.Core this method use reflection and could became broken after EF.Core update. + /// Due to unavailability of integration API in EF Core this method use reflection and could became broken after EF Core update. /// - /// EF.Core query. + /// EF Core query. /// Current instance. public virtual DbContext? GetCurrentContext(IQueryable query) { @@ -1046,10 +1045,10 @@ static bool IsEnumerableType(Type type, MappingSchema mappingSchema) } /// - /// Extracts EF.Core connection information object from . + /// Extracts EF Core connection information object from . /// /// instance. - /// EF.Core connection data. + /// EF Core connection data. public virtual EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options) { var relational = options?.Extensions.OfType().FirstOrDefault(); @@ -1061,10 +1060,10 @@ public virtual EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options } /// - /// Extracts EF.Core data model instance from . + /// Extracts EF Core data model instance from . /// /// instance. - /// EF.Core data model instance. + /// EF Core data model instance. public virtual IModel? ExtractModel(IDbContextOptions? options) { var coreOptions = options?.Extensions.OfType().FirstOrDefault(); diff --git a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs index 634131a..b932655 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SQLite.Tests/Models/ForMapping/ForMappingContext.cs @@ -16,9 +16,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(b => { b.HasKey(e => e.Id); - - b.Property(e => e.Id) - .HasAnnotation("Sqlite:Autoincrement", true); }); modelBuilder.Entity(b => diff --git a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs index 2f25e2e..927a764 100644 --- a/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs +++ b/Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs @@ -310,10 +310,7 @@ public void TestKey() { using (var ctx = CreateContext(false)) { - var dependencies = ctx.GetService(); - var mappingSource = ctx.GetService(); - var converters = ctx.GetService(); - var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, mappingSource); + var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx); var customerPk = ms.GetAttribute(typeof(Customer), MemberHelper.MemberOf(c => c.CustomerId)); @@ -330,10 +327,7 @@ public void TestAssociations() { using (var ctx = CreateContext(false)) { - var dependencies = ctx.GetService(); - var mappingSource = ctx.GetService(); - var converters = ctx.GetService(); - var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, converters, dependencies, null); + var ms = LinqToDBForEFTools.GetMappingSchema(ctx.Model, ctx); var associationOrder = ms.GetAttribute(typeof(Customer), MemberHelper.MemberOf(c => c.Orders)); diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 706cc27..2accba6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,8 @@ variables: solution: 'linq2db.EFCore.sln' build_configuration: 'Release' - assemblyVersion: 3.11.0 - nugetVersion: 3.11.0 + assemblyVersion: 3.11.1 + nugetVersion: 3.11.1 artifact_nugets: 'nugets' # build on commits to important branches (master + release branches):