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

Commit 769e319

Browse files
authored
- add missing xml docs (#79)
- enable C#9 and NRT - fix warnings
1 parent 0ef48b4 commit 769e319

File tree

79 files changed

+1769
-2463
lines changed

Some content is hidden

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

79 files changed

+1769
-2463
lines changed

Build/linq2db.Default.props

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@
22
<PropertyGroup>
33
<Version>5.0.2</Version>
44

5-
<Description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</Description>
6-
<Title>Linq to DB (linq2db) extensions for Entity Framework Core</Title>
7-
<AssemblyTitle>$(Title)</AssemblyTitle>
85
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
96
<Product>Linq to DB</Product>
107
<Company>linq2db.net</Company>
118
<Copyright>2002-2020 linq2db.net</Copyright>
129
<RepositoryUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</RepositoryUrl>
1310
<RepositoryType>git</RepositoryType>
1411

15-
<AppDesignerFolder>Properties</AppDesignerFolder>
16-
<LangVersion>8.0</LangVersion>
17-
<Nullable>disable</Nullable>
12+
<LangVersion>9.0</LangVersion>
13+
<Nullable>enable</Nullable>
1814
<WarningLevel>4</WarningLevel>
1915
<ErrorReport>prompt</ErrorReport>
20-
<NoWarn>1701;1591</NoWarn>
16+
<AnalysisLevel>preview</AnalysisLevel>
2117

2218
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
2319
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

Build/linq2db.Tests.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<Project>
2+
<Import Project="linq2db.Default.props" />
3+
24
<PropertyGroup>
35
<!--<TargetFrameworks>net5.0</TargetFrameworks>-->
46
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>

Source/LinqToDB.EntityFrameworkCore/EFConnectionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class EFConnectionInfo
1010
/// <summary>
1111
/// Gets or sets database connection instance.
1212
/// </summary>
13-
public DbConnection Connection { get; set; }
13+
public DbConnection? Connection { get; set; }
1414

1515
/// <summary>
1616
/// Gets or sets database connection string.
1717
/// </summary>
18-
public string ConnectionString { get; set; }
18+
public string? ConnectionString { get; set; }
1919
}
2020
}

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ namespace LinqToDB.EntityFrameworkCore
2929
/// </summary>
3030
internal class EFCoreMetadataReader : IMetadataReader
3131
{
32-
readonly IModel _model;
33-
private readonly RelationalSqlTranslatingExpressionVisitorDependencies _dependencies;
34-
private readonly IRelationalTypeMappingSource _mappingSource;
35-
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute> _calculatedExtensions = new ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute>();
36-
private readonly IDiagnosticsLogger<DbLoggerCategory.Query> _logger;
37-
38-
public EFCoreMetadataReader(IModel model,
39-
RelationalSqlTranslatingExpressionVisitorDependencies dependencies,
40-
IRelationalTypeMappingSource mappingSource,
41-
IDiagnosticsLogger<DbLoggerCategory.Query> logger
42-
)
32+
readonly IModel? _model;
33+
private readonly RelationalSqlTranslatingExpressionVisitorDependencies? _dependencies;
34+
private readonly IRelationalTypeMappingSource? _mappingSource;
35+
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?> _calculatedExtensions = new ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?>();
36+
private readonly IDiagnosticsLogger<DbLoggerCategory.Query>? _logger;
37+
38+
public EFCoreMetadataReader(
39+
IModel? model,
40+
RelationalSqlTranslatingExpressionVisitorDependencies? dependencies,
41+
IRelationalTypeMappingSource? mappingSource,
42+
IDiagnosticsLogger<DbLoggerCategory.Query>? logger)
4343
{
4444
_model = model;
4545
_dependencies = dependencies;
@@ -114,7 +114,7 @@ public T[] GetAttributes<T>(Type type, bool inherit = true) where T : Attribute
114114
return Array.Empty<T>();
115115
}
116116

117-
static bool CompareProperty(MemberInfo property, MemberInfo memberInfo)
117+
static bool CompareProperty(MemberInfo? property, MemberInfo memberInfo)
118118
{
119119
if (property == memberInfo)
120120
return true;
@@ -133,13 +133,11 @@ static bool CompareProperty(MemberInfo property, MemberInfo memberInfo)
133133
return false;
134134
}
135135

136-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
137136
static bool CompareProperty(IProperty property, MemberInfo memberInfo)
138137
{
139138
return CompareProperty(property.GetIdentifyingMemberInfo(), memberInfo);
140139
}
141140

142-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
143141
public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = true) where T : Attribute
144142
{
145143
if (typeof(Expression).IsSameOrParentOf(type))
@@ -164,9 +162,11 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
164162
.FirstOrDefault(v => CompareProperty(v.p, memberInfo))?.index ?? 0;
165163
}
166164

165+
var storeObjectId = StoreObjectIdentifier.Create(et, StoreObjectType.Table);
166+
167167
return new T[]{(T)(Attribute) new ColumnAttribute
168168
{
169-
Name = prop.GetColumnName(),
169+
Name = prop.GetColumnName(storeObjectId!.Value),
170170
Length = prop.GetMaxLength() ?? 0,
171171
CanBeNull = prop.IsNullable,
172172
DbType = prop.GetColumnType(),
@@ -314,7 +314,7 @@ class SqlTransparentExpression : SqlExpression
314314
{
315315
public Expression Expression { get; }
316316

317-
public SqlTransparentExpression(Expression expression, RelationalTypeMapping typeMapping) : base(expression.Type, typeMapping)
317+
public SqlTransparentExpression(Expression expression, RelationalTypeMapping? typeMapping) : base(expression.Type, typeMapping)
318318
{
319319
Expression = expression;
320320
}
@@ -325,16 +325,16 @@ protected override void Print(ExpressionPrinter expressionPrinter)
325325
}
326326
}
327327

328-
private Sql.ExpressionAttribute GetDbFunctionFromMethodCall(Type type, MethodInfo methodInfo)
328+
private Sql.ExpressionAttribute? GetDbFunctionFromMethodCall(Type type, MethodInfo methodInfo)
329329
{
330330
if (_dependencies == null || _model == null)
331331
return null;
332332

333-
methodInfo = (MethodInfo) type.GetMemberEx(methodInfo) ?? methodInfo;
333+
methodInfo = (MethodInfo?) type.GetMemberEx(methodInfo) ?? methodInfo;
334334

335335
var found = _calculatedExtensions.GetOrAdd(methodInfo, mi =>
336336
{
337-
EFCoreExpressionAttribute result = null;
337+
EFCoreExpressionAttribute? result = null;
338338

339339
if (!methodInfo.IsGenericMethodDefinition && !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
340340
{
@@ -364,19 +364,19 @@ private Sql.ExpressionAttribute GetDbFunctionFromMethodCall(Type type, MethodInf
364364
return found;
365365
}
366366

367-
private Sql.ExpressionAttribute GetDbFunctionFromProperty(Type type, PropertyInfo propInfo)
367+
private Sql.ExpressionAttribute? GetDbFunctionFromProperty(Type type, PropertyInfo propInfo)
368368
{
369369
if (_dependencies == null || _model == null)
370370
return null;
371371

372-
propInfo = (PropertyInfo) type.GetMemberEx(propInfo) ?? propInfo;
372+
propInfo = (PropertyInfo?) type.GetMemberEx(propInfo) ?? propInfo;
373373

374374
var found = _calculatedExtensions.GetOrAdd(propInfo, mi =>
375375
{
376-
EFCoreExpressionAttribute result = null;
376+
EFCoreExpressionAttribute? result = null;
377377

378-
if ((propInfo.GetMethod?.IsStatic != true)
379-
&& !(mi is DynamicColumnInfo)
378+
if ((propInfo.GetMethod?.IsStatic != true)
379+
&& !(mi is DynamicColumnInfo)
380380
&& !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
381381
{
382382
var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource?.FindMapping(propInfo));
@@ -397,7 +397,7 @@ private Sql.ExpressionAttribute GetDbFunctionFromProperty(Type type, PropertyInf
397397

398398
private static EFCoreExpressionAttribute ConvertToExpressionAttribute(MemberInfo memberInfo, Expression newExpression, Expression[] parameters)
399399
{
400-
string PrepareExpressionText(Expression expr)
400+
string PrepareExpressionText(Expression? expr)
401401
{
402402
var idx = Array.IndexOf(parameters, expr);
403403
if (idx >= 0)

Source/LinqToDB.EntityFrameworkCore/EFProviderInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ public class EFProviderInfo
1313
/// <summary>
1414
/// Gets or sets database connection instance.
1515
/// </summary>
16-
public DbConnection Connection { get; set; }
16+
public DbConnection? Connection { get; set; }
1717

1818
/// <summary>
1919
/// Gets or sets EF.Core context instance.
2020
/// </summary>
21-
public DbContext Context { get; set; }
21+
public DbContext? Context { get; set; }
2222

2323
/// <summary>
2424
/// Gets or sets EF.Core context options instance.
2525
/// </summary>
26-
public IDbContextOptions Options { get; set; }
26+
public IDbContextOptions? Options { get; set; }
2727
}
2828
}

Source/LinqToDB.EntityFrameworkCore/ILinqToDBForEFTools.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface ILinqToDBForEFTools
3333
/// <param name="providerInfo">Provider information, extracted from EF.Core.</param>
3434
/// <param name="connectionInfo">Database connection information.</param>
3535
/// <returns>LINQ TO DB provider instance.</returns>
36-
IDataProvider GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo);
36+
IDataProvider? GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo);
3737

3838
/// <summary>
3939
/// Creates metadata provider for specified EF.Core data model.
@@ -43,9 +43,11 @@ public interface ILinqToDBForEFTools
4343
/// <param name="mappingSource"></param>
4444
/// <param name="logger"></param>
4545
/// <returns>LINQ To DB metadata provider for specified EF.Core model. Can return <c>null</c>.</returns>
46-
IMetadataReader CreateMetadataReader(IModel model, RelationalSqlTranslatingExpressionVisitorDependencies dependencies,
47-
IRelationalTypeMappingSource mappingSource,
48-
IDiagnosticsLogger<DbLoggerCategory.Query> logger);
46+
IMetadataReader? CreateMetadataReader(
47+
IModel? model,
48+
RelationalSqlTranslatingExpressionVisitorDependencies? dependencies,
49+
IRelationalTypeMappingSource? mappingSource,
50+
IDiagnosticsLogger<DbLoggerCategory.Query>? logger);
4951

5052
/// <summary>
5153
/// Creates mapping schema using provided EF.Core data model and metadata provider.
@@ -63,14 +65,14 @@ IMetadataReader CreateMetadataReader(IModel model, RelationalSqlTranslatingExpre
6365
/// <param name="metadataReader">Additional optional LINQ To DB database metadata provider.</param>
6466
/// <param name="convertorSelector">EF Core registry for type conversion.</param>
6567
/// <returns>Mapping schema for provided EF.Core model.</returns>
66-
MappingSchema GetMappingSchema(IModel model, IMetadataReader metadataReader, IValueConverterSelector convertorSelector);
68+
MappingSchema GetMappingSchema(IModel model, IMetadataReader? metadataReader, IValueConverterSelector? convertorSelector);
6769

6870
/// <summary>
6971
/// Returns EF.Core <see cref="IDbContextOptions"/> for specific <see cref="DbContext"/> instance.
7072
/// </summary>
7173
/// <param name="context">EF.Core <see cref="DbContext"/> instance.</param>
7274
/// <returns><see cref="IDbContextOptions"/> instance.</returns>
73-
IDbContextOptions GetContextOptions(DbContext context);
75+
IDbContextOptions? GetContextOptions(DbContext? context);
7476

7577
/// <summary>
7678
/// Transforms EF.Core expression tree to LINQ To DB expression.
@@ -80,35 +82,35 @@ IMetadataReader CreateMetadataReader(IModel model, RelationalSqlTranslatingExpre
8082
/// <param name="ctx">Optional DbContext instance.</param>
8183
/// <param name="model">EF.Core data model instance.</param>
8284
/// <returns>Transformed expression.</returns>
83-
Expression TransformExpression(Expression expression, IDataContext dc, DbContext ctx, IModel model);
85+
Expression TransformExpression(Expression expression, IDataContext dc, DbContext? ctx, IModel? model);
8486

8587
/// <summary>
8688
/// Extracts <see cref="DbContext"/> instance from <see cref="IQueryable"/> object.
8789
/// </summary>
8890
/// <param name="query">EF.Core query.</param>
8991
/// <returns>Current <see cref="DbContext"/> instance.</returns>
90-
DbContext GetCurrentContext(IQueryable query);
92+
DbContext? GetCurrentContext(IQueryable query);
9193

9294
/// <summary>
9395
/// Extracts EF.Core connection information object from <see cref="IDbContextOptions"/>.
9496
/// </summary>
9597
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
9698
/// <returns>EF.Core connection data.</returns>
97-
EFConnectionInfo ExtractConnectionInfo(IDbContextOptions options);
99+
EFConnectionInfo ExtractConnectionInfo(IDbContextOptions? options);
98100

99101
/// <summary>
100102
/// Extracts EF.Core data model instance from <see cref="IDbContextOptions"/>.
101103
/// </summary>
102104
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
103105
/// <returns>EF.Core data model instance.</returns>
104-
IModel ExtractModel(IDbContextOptions options);
106+
IModel? ExtractModel(IDbContextOptions? options);
105107

106108
/// <summary>
107109
/// Creates logger used for logging Linq To DB connection calls.
108110
/// </summary>
109111
/// <param name="options"><see cref="IDbContextOptions"/> instance.</param>
110112
/// <returns>Logger instance.</returns>
111-
ILogger CreateLogger(IDbContextOptions options);
113+
ILogger? CreateLogger(IDbContextOptions? options);
112114

113115
/// <summary>
114116
/// Logs DataConnection information.

Source/LinqToDB.EntityFrameworkCore/Internal/EFCoreExpressionAttribute.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@
77

88
namespace LinqToDB.EntityFrameworkCore.Internal
99
{
10+
/// <summary>
11+
/// Maps linq2db exression.
12+
/// </summary>
1013
public class EFCoreExpressionAttribute : Sql.ExpressionAttribute
1114
{
15+
/// <summary>
16+
/// Creates instance of expression mapper.
17+
/// </summary>
18+
/// <param name="expression">Mapped expression.</param>
1219
public EFCoreExpressionAttribute(string expression) : base(expression)
1320
{
1421
}
1522

16-
public override ISqlExpression GetExpression(IDataContext dataContext, SelectQuery query,
17-
Expression expression, Func<Expression, ColumnDescriptor, ISqlExpression> converter)
23+
/// <inheritdoc cref="Sql.ExpressionAttribute.GetExpression(IDataContext, SelectQuery, System.Linq.Expressions.Expression, Func{Expression, ColumnDescriptor?, ISqlExpression})" />
24+
public override ISqlExpression GetExpression(
25+
IDataContext dataContext,
26+
SelectQuery query,
27+
Expression expression,
28+
Func<Expression, ColumnDescriptor?, ISqlExpression> converter)
1829
{
1930
var knownExpressions = new List<Expression>();
2031
if (expression.NodeType == ExpressionType.Call)
@@ -30,9 +41,9 @@ public override ISqlExpression GetExpression(IDataContext dataContext, SelectQue
3041
knownExpressions.Add(me.Expression);
3142
}
3243

33-
var pams = new List<ISqlExpression>(knownExpressions.Select(_ => (ISqlExpression) null));
44+
var pams = new List<ISqlExpression?>(knownExpressions.Select(_ => (ISqlExpression?) null));
3445

35-
_ = Sql.ExtensionAttribute.ResolveExpressionValues(Expression,
46+
_ = Sql.ExtensionAttribute.ResolveExpressionValues(Expression!,
3647
(v, d) =>
3748
{
3849
var idx = int.Parse(v);
@@ -44,7 +55,7 @@ public override ISqlExpression GetExpression(IDataContext dataContext, SelectQue
4455
});
4556

4657
var parameters = pams.Select(p => p ?? new SqlExpression("!!!")).ToArray();
47-
return new SqlExpression(expression.Type, Expression, Precedence, parameters);
58+
return new SqlExpression(expression.Type, Expression!, Precedence, parameters);
4859
}
4960
}
5061
}

0 commit comments

Comments
 (0)