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

Commit 152aa35

Browse files
authored
Merge pull request #273 from linq2db/master
Release 7.0.0
2 parents a44cbcb + 7393c62 commit 152aa35

File tree

96 files changed

+1605
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1605
-892
lines changed

.gitignore

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
1-
#ignore thumbnails created by windows
2-
Thumbs.db
3-
#Ignore files build by Visual Studio
4-
*.obj
5-
*.pdb
1+
#Ignore files build by IDE
62
*.user
7-
*.aps
8-
*.pch
9-
*.vspscc
10-
*_i.c
11-
*_p.c
12-
*.ncb
13-
*.suo
14-
*.tlb
15-
*.tlh
16-
*.bak
17-
*.cache
18-
*.ilk
19-
*.log
20-
*.cs.ide
21-
[Bb]in
22-
[Dd]ebug*/
23-
*.lib
24-
*.sbr
3+
bin/
254
obj/
26-
[Rr]elease*/
275
_ReSharper*/
28-
[Tt]est[Rr]esult*
29-
linq2db.sln.docstates
30-
Tests/**/UserDataProviders*.*
31-
NuGet/*.nupkg
32-
!*.dll
33-
!*.exe
34-
!*.pdb
35-
linq2db.sln.ide/graph
36-
linq2db.sln.ide/
37-
!Redist/**
38-
/packages
396
/.vs/*
40-
*.lock.json
41-
/api
42-
/linq2db.github.io
43-
#cake
44-
/tools
45-
/.tools
7+
/.tools/
468
/.idea/

Build/linq2db.Default.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>5.13.0</Version>
3+
<Version>7.0.0</Version>
44

55
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
66
<Product>Linq to DB</Product>
@@ -27,8 +27,11 @@
2727
<GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
2828
<GenerateAssemblyFileVersionAttribute>true</GenerateAssemblyFileVersionAttribute>
2929
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
30+
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
3031

3132
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
33+
34+
<TargetFrameworks>net6.0</TargetFrameworks>
3235
</PropertyGroup>
3336

3437
<PropertyGroup>

Build/linq2db.Tests.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<Import Project="linq2db.Default.props" />
33

44
<PropertyGroup>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFrameworks>net7.0</TargetFrameworks>
66
</PropertyGroup>
7-
7+
88
<ItemGroup>
99
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1010
<PackageReference Include="NUnit3TestAdapter">

Directory.Packages.props

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
4-
<PackageVersion Include="NUnit3TestAdapter" Version="4.2.1" />
3+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
4+
<PackageVersion Include="NUnit3TestAdapter" Version="4.3.0" />
55
<PackageVersion Include="NUnit" Version="3.13.3" />
6-
<PackageVersion Include="FluentAssertions" Version="6.6.0" />
6+
<PackageVersion Include="FluentAssertions" Version="6.8.0" />
77

88
<PackageVersion Include="linq2db" Version="4.3.0" />
99
<PackageVersion Include="linq2db.Tools" Version="4.3.0" />
1010

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

13-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.17" />
14-
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.17" />
13+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
14+
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" />
1515

16-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
17-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
16+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
17+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
1818

19-
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.4" />
20-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.17" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />
19+
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
20+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />
22+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
2323

24-
<PackageVersion Include="EntityFrameworkCore.FSharp" Version="5.0.3" />
25-
<PackageVersion Include="FSharp.Core" Version="6.0.5" />
24+
<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
25+
<PackageVersion Include="FSharp.Core" Version="7.0.0" />
2626
</ItemGroup>
2727
</Project>

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Linq to DB (linq2db) extensions for Entity Framework Core</title>
66
<authors>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</authors>
77
<owners>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</owners>
8-
<copyright>Copyright © 2020-2021 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
8+
<copyright>Copyright © 2020-2022 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
99
<description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</description>
1010
<summary />
1111
<tags>linq linq2db LinqToDB ORM database entity-framework-core EntityFrameworkCore EFCore DB SQL SqlServer SqlCe SqlServerCe MySql Firebird SQLite Oracle ODP PostgreSQL DB2</tags>
@@ -14,8 +14,8 @@
1414
<projectUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</projectUrl>
1515
<license type="file">MIT-LICENSE.txt</license>
1616
<dependencies>
17-
<group targetFramework=".NETStandard2.1">
18-
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="5.0.17" />
17+
<group targetFramework="net6.0">
18+
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="7.0.0" />
1919
<dependency id="linq2db" version="4.3.0" />
2020
</group>
2121
</dependencies>

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ LinqToDBForEFTools.Initialize();
3939

4040
After that you can just call DbContext and IQueryable extension methods, provided by `LINQ To DB`.
4141

42+
You can also register additional options (like interceptors) for LinqToDB during EF context registration, here is an example:
43+
44+
```cs
45+
var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
46+
optionsBuilder.UseSqlite();
47+
optionsBuilder.UseLinqToDb(builder =>
48+
{
49+
builder.AddInterceptor(new MyCommandInterceptor());
50+
});
51+
```
52+
4253
There are many extensions for CRUD Operations missing in vanilla EF ([watch our video](https://www.youtube.com/watch?v=m--oX73EGeQ)):
4354

4455
```cs

Source/LinqToDB.EntityFrameworkCore/EFConnectionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace LinqToDB.EntityFrameworkCore
55
/// <summary>
66
/// Contains database connectivity information, extracted from EF.Core.
77
/// </summary>
8-
public class EFConnectionInfo
8+
public sealed class EFConnectionInfo
99
{
1010
/// <summary>
1111
/// Gets or sets database connection instance.

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Concurrent;
43
using System.Collections.Generic;
54
using System.Data;
@@ -31,7 +30,7 @@ namespace LinqToDB.EntityFrameworkCore
3130
/// <summary>
3231
/// LINQ To DB metadata reader for EF.Core model.
3332
/// </summary>
34-
internal class EFCoreMetadataReader : IMetadataReader
33+
internal sealed class EFCoreMetadataReader : IMetadataReader
3534
{
3635
readonly IModel? _model;
3736
private readonly RelationalSqlTranslatingExpressionVisitorDependencies? _dependencies;
@@ -40,8 +39,7 @@ internal class EFCoreMetadataReader : IMetadataReader
4039
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?> _calculatedExtensions = new();
4140
private readonly IDiagnosticsLogger<DbLoggerCategory.Query>? _logger;
4241

43-
public EFCoreMetadataReader(
44-
IModel? model, IInfrastructure<IServiceProvider>? accessor)
42+
public EFCoreMetadataReader(IModel? model, IInfrastructure<IServiceProvider>? accessor)
4543
{
4644
_model = model;
4745
if (accessor != null)
@@ -61,7 +59,7 @@ public T[] GetAttributes<T>(Type type, bool inherit = true) where T : Attribute
6159
if (typeof(T) == typeof(TableAttribute))
6260
{
6361
var storeObjectId = GetStoreObjectIdentifier(et);
64-
return new[] { (T)(Attribute)new TableAttribute(storeObjectId!.Value.Name) { Schema = storeObjectId!.Value.Schema } };
62+
return new[] { (T)(Attribute)new TableAttribute() { Schema = storeObjectId?.Schema, Name = storeObjectId?.Name } };
6563
}
6664
if (typeof(T) == typeof(QueryFilterAttribute))
6765
{
@@ -208,7 +206,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
208206

209207
if (prop != null)
210208
{
211-
var discriminator = et.GetDiscriminatorProperty();
209+
var discriminator = et.FindDiscriminatorProperty();
212210

213211
var isPrimaryKey = prop.IsPrimaryKey();
214212
var primaryKeyOrder = 0;
@@ -225,14 +223,14 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
225223
if (_annotationProvider != null && storeObjectId != null)
226224
{
227225
if (prop.FindColumn(storeObjectId.Value) is IColumn column)
228-
annotations = annotations.Concat(_annotationProvider.For(column));
226+
annotations = annotations.Concat(_annotationProvider.For(column, false));
229227
}
230228

231229
var isIdentity = annotations
232230
.Any(a =>
233231
{
234232
if (a.Name.EndsWith(":ValueGenerationStrategy"))
235-
return a.Value?.ToString()!.Contains("Identity") == true;
233+
return a.Value?.ToString()?.Contains("Identity") == true;
236234

237235
if (a.Name.EndsWith(":Autoincrement"))
238236
return a.Value is bool b && b;
@@ -242,7 +240,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
242240
{
243241
if (a.Value is string str)
244242
{
245-
return str.ToLower().Contains("nextval");
243+
return str.ToLowerInvariant().Contains("nextval");
246244
}
247245
}
248246

@@ -259,7 +257,8 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
259257
}
260258
else
261259
{
262-
dataType = SqlDataType.GetDataType(typeMapping.ClrType).Type.DataType;
260+
var ms = _model != null ? LinqToDBForEFTools.GetMappingSchema(_model, null) : MappingSchema.Default;
261+
dataType = ms.GetDataType(typeMapping.ClrType).Type.DataType;
263262
}
264263
}
265264

@@ -278,7 +277,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
278277
{
279278
(T)(Attribute)new ColumnAttribute
280279
{
281-
Name = prop.GetColumnName(storeObjectId!.Value),
280+
Name = storeObjectId != null ? prop.GetColumnName(storeObjectId.Value) : null,
282281
Length = prop.GetMaxLength() ?? 0,
283282
CanBeNull = prop.IsNullable,
284283
DbType = prop.GetColumnType(),
@@ -408,7 +407,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
408407
return Array.Empty<T>();
409408
}
410409

411-
class ValueConverter : IValueConverter
410+
sealed class ValueConverter : IValueConverter
412411
{
413412
public ValueConverter(
414413
LambdaExpression convertToProviderExpression,
@@ -425,7 +424,7 @@ public ValueConverter(
425424

426425
}
427426

428-
class SqlTransparentExpression : SqlExpression
427+
sealed class SqlTransparentExpression : SqlExpression
429428
{
430429
public Expression Expression { get; }
431430

@@ -439,7 +438,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
439438
expressionPrinter.Print(Expression);
440439
}
441440

442-
protected bool Equals(SqlTransparentExpression other)
441+
private bool Equals(SqlTransparentExpression other)
443442
{
444443
return ReferenceEquals(this, other);
445444
}
@@ -596,23 +595,24 @@ string PrepareExpressionText(Expression? expr)
596595
return text;
597596
}
598597

598+
// https://github.com/npgsql/efcore.pg/blob/main/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs
599599
if (newExpression.GetType().Name == "PostgresBinaryExpression")
600600
{
601601
// Handling NpgSql's PostgresBinaryExpression
602602

603-
var left = newExpression.GetType().GetProperty("Left")?.GetValue(newExpression) as Expression;
604-
var right = newExpression.GetType().GetProperty("Right")?.GetValue(newExpression) as Expression;
603+
var left = (Expression)newExpression.GetType().GetProperty("Left")!.GetValue(newExpression)!;
604+
var right = (Expression)newExpression.GetType().GetProperty("Right")!.GetValue(newExpression)!;
605605

606-
var operand = newExpression.GetType().GetProperty("OperatorType")?.GetValue(newExpression)!.ToString();
606+
var operand = newExpression.GetType().GetProperty("OperatorType")!.GetValue(newExpression)!.ToString()!;
607607

608608
var operandExpr = operand switch
609609
{
610610
"Contains"
611-
when left!.Type.Name == "NpgsqlInetTypeMapping" ||
611+
when left.Type.Name == "NpgsqlInetTypeMapping" ||
612612
left.Type.Name == "NpgsqlCidrTypeMapping"
613613
=> ">>",
614614
"ContainedBy"
615-
when left!.Type.Name == "NpgsqlInetTypeMapping" ||
615+
when left.Type.Name == "NpgsqlInetTypeMapping" ||
616616
left.Type.Name == "NpgsqlCidrTypeMapping"
617617
=> "<<",
618618
"Contains" => "@>",
@@ -674,7 +674,7 @@ private static Expression UnwrapConverted(Expression expr)
674674
if (expr is SqlFunctionExpression func)
675675
{
676676
if (string.Equals(func.Name, "COALESCE", StringComparison.InvariantCultureIgnoreCase) &&
677-
func.Arguments!.Count == 2 && func.Arguments[1].NodeType == ExpressionType.Extension)
677+
func.Arguments?.Count == 2 && func.Arguments[1].NodeType == ExpressionType.Extension)
678678
return UnwrapConverted(func.Arguments[0]);
679679
}
680680

Source/LinqToDB.EntityFrameworkCore/EFProviderInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace LinqToDB.EntityFrameworkCore
88
/// <summary>
99
/// Required integration information about underlying database provider, extracted from EF.Core.
1010
/// </summary>
11-
public class EFProviderInfo
11+
public sealed class EFProviderInfo
1212
{
1313
/// <summary>
1414
/// Gets or sets database connection instance.

Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,5 @@ public interface ILinqToDBForEFTools
119119
/// Entities will be attached only if AsNoTracking() is not used in query and DbContext is configured to track entities.
120120
/// </summary>
121121
bool EnableChangeTracker { get; set; }
122-
123122
}
124123
}

0 commit comments

Comments
 (0)