Skip to content

Commit

Permalink
Merge pull request #235 from linq2db/version6
Browse files Browse the repository at this point in the history
Version 6.8.0
  • Loading branch information
sdanyliv authored May 30, 2022
2 parents 9fc82fd + 6963a68 commit cc95fae
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 164 deletions.
4 changes: 2 additions & 2 deletions Build/linq2db.Default.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>
<PropertyGroup>
<Version>6.7.1</Version>
<Version>6.8.0</Version>

<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
<Product>Linq to DB</Product>
<Company>linq2db.net</Company>
<Copyright>2002-2021 linq2db.net</Copyright>
<Copyright>2002-2022 linq2db.net</Copyright>
<RepositoryUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</RepositoryUrl>
<RepositoryType>git</RepositoryType>

Expand Down
24 changes: 12 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageVersion Include="NUnit" Version="3.13.2" />
<PackageVersion Include="FluentAssertions" Version="6.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="FluentAssertions" Version="6.6.0" />

<PackageVersion Include="linq2db" Version="3.7.0" />
<PackageVersion Include="linq2db.Tools" Version="3.7.0" />
<PackageVersion Include="linq2db" Version="4.0.1" />
<PackageVersion Include="linq2db.Tools" Version="4.0.1" />

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />

<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.5" />

<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />

<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="linq2db" value="https://pkgs.dev.azure.com/linq2db/linq2db/_packaging/linq2db/nuget/v3/index.json" />
</packageSources>
</configuration>
<packageSourceMapping>
<packageSource key="NuGet">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
4 changes: 2 additions & 2 deletions NuGet/linq2db.EntityFrameworkCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<license type="file">MIT-LICENSE.txt</license>
<dependencies>
<group targetFramework="net6.0">
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.0" />
<dependency id="linq2db" version="3.7.0" />
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.5" />
<dependency id="linq2db" version="4.0.1" />
</group>
</dependencies>
</metadata>
Expand Down
15 changes: 6 additions & 9 deletions Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
Expand All @@ -20,11 +19,11 @@

namespace LinqToDB.EntityFrameworkCore
{
using Mapping;
using Metadata;
using Extensions;
using Common;
using Extensions;
using Internal;
using Mapping;
using Metadata;
using SqlQuery;
using SqlExpression = SqlExpression;

Expand Down Expand Up @@ -321,8 +320,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
{
ThisKey = thisKey,
OtherKey = otherKey,
CanBeNull = !fk.IsRequiredDependent,
IsBackReference = false
CanBeNull = !fk.IsRequiredDependent
});
}
else
Expand All @@ -333,8 +331,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
{
ThisKey = thisKey,
OtherKey = otherKey,
CanBeNull = !fk.IsRequired,
IsBackReference = true
CanBeNull = !fk.IsRequired
});
}
}
Expand Down Expand Up @@ -578,7 +575,7 @@ string PrepareExpressionText(Expression? expr)
if (expr is SqlFunctionExpression sqlFunction)
{
var text = sqlFunction.Name;
if (!sqlFunction.Schema.IsNullOrEmpty())
if (!string.IsNullOrEmpty(sqlFunction.Schema))
text = sqlFunction.Schema + "." + sqlFunction.Name;

if (!sqlFunction.IsNiladic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public EFCoreExpressionAttribute(string expression) : base(expression)
{
}

/// <inheritdoc />
/// <inheritdoc/>
public override ISqlExpression? GetExpression<TContext>(
TContext context,
IDataContext dataContext,
Expand Down
16 changes: 8 additions & 8 deletions Source/LinqToDB.EntityFrameworkCore/LinqToDBExtensionsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,30 @@ public Task<long> LongCountAsync<TSource>(
=> EntityFrameworkQueryableExtensions.LongCountAsync(source, predicate, token);

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MinAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public Task<TSource> MinAsync<TSource>(
public Task<TSource?> MinAsync<TSource>(
IQueryable<TSource> source,
CancellationToken token)
=> EntityFrameworkQueryableExtensions.MinAsync(source, token);
=> EntityFrameworkQueryableExtensions.MinAsync(source, token)!;

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MinAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
public Task<TResult> MinAsync<TSource,TResult>(
public Task<TResult?> MinAsync<TSource,TResult>(
IQueryable<TSource> source,
Expression<Func<TSource,TResult>> selector,
CancellationToken token)
=> EntityFrameworkQueryableExtensions.MinAsync(source, selector, token);
=> EntityFrameworkQueryableExtensions.MinAsync(source, selector, token)!;

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MaxAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public Task<TSource> MaxAsync<TSource>(
public Task<TSource?> MaxAsync<TSource>(
IQueryable<TSource> source,
CancellationToken token)
=> EntityFrameworkQueryableExtensions.MaxAsync(source, token);
=> EntityFrameworkQueryableExtensions.MaxAsync(source, token)!;

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.MaxAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
public Task<TResult> MaxAsync<TSource,TResult>(
public Task<TResult?> MaxAsync<TSource,TResult>(
IQueryable<TSource> source,
Expression<Func<TSource,TResult>> selector,
CancellationToken token)
=> EntityFrameworkQueryableExtensions.MaxAsync(source, selector, token);
=> EntityFrameworkQueryableExtensions.MaxAsync(source, selector, token)!;

#region SumAsync

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,26 @@ public static Task<long> LongCountAsyncLinqToDB<TSource>(
=> AsyncExtensions.LongCountAsync(source.ToLinqToDB(), predicate, token);

/// <inheritdoc cref="AsyncExtensions.MinAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public static Task<TSource> MinAsyncLinqToDB<TSource>(
public static Task<TSource?> MinAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default)
=> AsyncExtensions.MinAsync(source.ToLinqToDB(), token);

/// <inheritdoc cref="AsyncExtensions.MinAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
public static Task<TResult> MinAsyncLinqToDB<TSource,TResult>(
public static Task<TResult?> MinAsyncLinqToDB<TSource,TResult>(
this IQueryable<TSource> source,
Expression<Func<TSource,TResult>> selector,
CancellationToken token = default)
=> AsyncExtensions.MinAsync(source.ToLinqToDB(), selector, token);

/// <inheritdoc cref="AsyncExtensions.MaxAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public static Task<TSource> MaxAsyncLinqToDB<TSource>(
public static Task<TSource?> MaxAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default)
=> AsyncExtensions.MaxAsync(source.ToLinqToDB(), token);

/// <inheritdoc cref="AsyncExtensions.MaxAsync{TSource, TResult}(IQueryable{TSource}, Expression{Func{TSource, TResult}}, CancellationToken)"/>
public static Task<TResult> MaxAsyncLinqToDB<TSource,TResult>(
public static Task<TResult?> MaxAsyncLinqToDB<TSource,TResult>(
this IQueryable<TSource> source,
Expression<Func<TSource,TResult>> selector,
CancellationToken token = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void InitializeSqlServerMapping()
var dateDiffStr = "DateDiff";
var dateDiffMethods = sqlServerMethods.Where(m => m.Name.StartsWith(dateDiffStr)).ToArray();

var dateDiffMethod = MemberHelper.MethodOf(() => Sql.DateDiff(Sql.DateParts.Day, null, null));
var dateDiffMethod = MemberHelper.MethodOf(() => Sql.DateDiff(Sql.DateParts.Day, (DateTime?)null, null));

foreach (var method in dateDiffMethods)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ namespace LinqToDB.EntityFrameworkCore
using DataProvider;
using Linq;
using Expressions;
using LinqToDB.Interceptors;
using System.Data.Common;

/// <summary>
/// linq2db EF.Core data connection.
/// </summary>
public class LinqToDBForEFToolsDataConnection : DataConnection, IExpressionPreprocessor
public class LinqToDBForEFToolsDataConnection : DataConnection, IExpressionPreprocessor, IEntityServiceInterceptor
{
readonly IModel? _model;
readonly Func<Expression, IDataContext, DbContext?, IModel?, Expression>? _transformFunc;
Expand Down Expand Up @@ -67,7 +69,7 @@ public LinqToDBForEFToolsDataConnection(
_transformFunc = transformFunc;
CopyDatabaseProperties();
if (LinqToDBForEFTools.EnableChangeTracker)
OnEntityCreated += OnEntityCreatedHandler;
AddInterceptor(this);
}

/// <summary>
Expand All @@ -80,18 +82,18 @@ public LinqToDBForEFToolsDataConnection(
/// <param name="transformFunc">Expression converter.</param>
public LinqToDBForEFToolsDataConnection(
DbContext? context,
[NotNull] IDataProvider dataProvider,
[NotNull] IDbTransaction transaction,
IModel? model,
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc
) : base(dataProvider, transaction)
[NotNull] IDataProvider dataProvider,
[NotNull] DbTransaction transaction,
IModel? model,
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc)
: base(dataProvider, transaction)
{
Context = context;
_model = model;
_transformFunc = transformFunc;
CopyDatabaseProperties();
if (LinqToDBForEFTools.EnableChangeTracker)
OnEntityCreated += OnEntityCreatedHandler;
AddInterceptor(this);
}

/// <summary>
Expand All @@ -105,7 +107,7 @@ public LinqToDBForEFToolsDataConnection(
public LinqToDBForEFToolsDataConnection(
DbContext? context,
[NotNull] IDataProvider dataProvider,
[NotNull] IDbConnection connection,
[NotNull] DbConnection connection,
IModel? model,
Func<Expression, IDataContext, DbContext?, IModel?, Expression>? transformFunc) : base(dataProvider, connection)
{
Expand All @@ -114,7 +116,7 @@ public LinqToDBForEFToolsDataConnection(
_transformFunc = transformFunc;
CopyDatabaseProperties();
if (LinqToDBForEFTools.EnableChangeTracker)
OnEntityCreated += OnEntityCreatedHandler;
AddInterceptor(this);
}

/// <summary>
Expand Down Expand Up @@ -157,7 +159,7 @@ public override bool Equals(object? obj)
return true;
}

if (obj.GetType() != this.GetType())
if (obj.GetType() != GetType())
{
return false;
}
Expand All @@ -174,34 +176,34 @@ public override int GetHashCode()
}
}

private void OnEntityCreatedHandler(EntityCreatedEventArgs args)
object IEntityServiceInterceptor.EntityCreated(EntityCreatedEventData eventData, object entity)
{
// Do not allow to store in ChangeTracker temporary tables
if ((args.TableOptions & TableOptions.IsTemporaryOptionSet) != 0)
return;
if ((eventData.TableOptions & TableOptions.IsTemporaryOptionSet) != 0)
return entity;

// Do not allow to store in ChangeTracker tables from different server
if (args.ServerName != null)
return;
if (eventData.ServerName != null)
return entity;

if (!LinqToDBForEFTools.EnableChangeTracker
|| !Tracking
|| Context!.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.NoTracking)
return;
return entity;

var type = args.Entity.GetType();
var type = entity.GetType();
if (_lastType != type)
{
_lastType = type;
_lastEntityType = Context.Model.FindEntityType(type);
}

if (_lastEntityType == null)
return;
return entity;

// Do not allow to store in ChangeTracker tables that has different name
if (args.TableName != _lastEntityType.GetTableName())
return;
if (eventData.TableName != _lastEntityType.GetTableName())
return entity;

if (_stateManager == null)
_stateManager = Context.GetService<IStateManager>();
Expand All @@ -220,16 +222,16 @@ private void OnEntityCreatedHandler(EntityCreatedEventArgs args)
});

if (retrievalFunc == null)
return;
return entity;

entry = retrievalFunc(_stateManager, args.Entity);
entry = retrievalFunc(_stateManager, entity);

if (entry == null)
{
entry = _stateManager.StartTrackingFromQuery(_lastEntityType, args.Entity, ValueBuffer.Empty);
entry = _stateManager.StartTrackingFromQuery(_lastEntityType, entity, ValueBuffer.Empty);
}

args.Entity = entry.Entity;
return entry.Entity;
}

private Func<IStateManager, object, InternalEntityEntry?>? CreateEntityRetrievalFunc(IEntityType entityType)
Expand Down
Loading

0 comments on commit cc95fae

Please sign in to comment.