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

Commit 7d2fb4f

Browse files
committed
Updated linq2db.EntityFrameworkCore to linq2db 3.0-preview2. EF Core to 3.1.3.
Unit tests reorganization.
1 parent 4ed5d68 commit 7d2fb4f

File tree

110 files changed

+10274
-10106
lines changed

Some content is hidden

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

110 files changed

+10274
-10106
lines changed

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,15 @@ private Sql.ExpressionAttribute GetDbFunctionFromMethodCall(Type type, MethodInf
243243

244244
if (!methodInfo.IsGenericMethodDefinition && !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
245245
{
246-
var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource.FindMapping(type));
246+
var value = Expression.Constant(DefaultValue.GetValue(type), type);
247+
248+
var objExpr = new SqlTransparentExpression(value, _mappingSource?.FindMapping(type));
247249
var parameterInfos = methodInfo.GetParameters();
248250
var parametersArray = parameterInfos
249251
.Select(p =>
250252
(SqlExpression)new SqlTransparentExpression(
251253
Expression.Constant(DefaultValue.GetValue(p.ParameterType), p.ParameterType),
252-
_mappingSource.FindMapping(p.ParameterType))).ToArray();
254+
_mappingSource?.FindMapping(p.ParameterType))).ToArray();
253255

254256
var newExpression = _dependencies.MethodCallTranslatorProvider.Translate(_model, objExpr, methodInfo, parametersArray);
255257
if (newExpression != null)
@@ -280,7 +282,7 @@ private Sql.ExpressionAttribute GetDbFunctionFromProperty(Type type, PropertyInf
280282

281283
if ((propInfo.GetMethod?.IsStatic != true) && !mi.GetCustomAttributes<Sql.ExpressionAttribute>().Any())
282284
{
283-
var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource.FindMapping(propInfo));
285+
var objExpr = new SqlTransparentExpression(Expression.Constant(DefaultValue.GetValue(type), type), _mappingSource?.FindMapping(propInfo));
284286

285287
var newExpression = _dependencies.MemberTranslatorProvider.Translate(objExpr, propInfo, propInfo.GetMemberType());
286288
if (newExpression != null)

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,16 @@ public static DataConnection CreateLinqToDbConnection(this DbContext context,
262262
if (transaction != null)
263263
{
264264
var dbTrasaction = transaction.GetDbTransaction();
265-
if (provider.IsCompatibleConnection(dbTrasaction.Connection))
265+
// TODO: we need API for testing current connection
266+
//if (provider.IsCompatibleConnection(dbTrasaction.Connection))
266267
dc = new LinqToDBForEFToolsDataConnection(context, provider, dbTrasaction, context.Model, TransformExpression);
267268
}
268269

269270
if (dc == null)
270271
{
271272
var dbConnection = context.Database.GetDbConnection();
272-
if (provider.IsCompatibleConnection(dbConnection))
273+
// TODO: we need API for testing current connection
274+
if (true /*provider.IsCompatibleConnection(dbConnection)*/)
273275
dc = new LinqToDBForEFToolsDataConnection(context, provider, dbConnection, context.Model, TransformExpression);
274276
else
275277
{
@@ -318,14 +320,17 @@ public static IDataContext CreateLinqToDbContext(this DbContext context,
318320
if (transaction != null)
319321
{
320322
var dbTransaction = transaction.GetDbTransaction();
321-
if (provider.IsCompatibleConnection(dbTransaction.Connection))
322-
dc = new LinqToDBForEFToolsDataConnection(context, provider, dbTransaction, context.Model, TransformExpression);
323+
324+
// TODO: we need API for testing current connection
325+
// if (provider.IsCompatibleConnection(dbTransaction.Connection))
326+
dc = new LinqToDBForEFToolsDataConnection(context, provider, dbTransaction, context.Model, TransformExpression);
323327
}
324328

325329
if (dc == null)
326330
{
327331
var dbConnection = context.Database.GetDbConnection();
328-
if (provider.IsCompatibleConnection(dbConnection))
332+
// TODO: we need API for testing current connection
333+
if (true /*provider.IsCompatibleConnection(dbConnection)*/)
329334
dc = new LinqToDBForEFToolsDataConnection(context, provider, context.Database.GetDbConnection(), context.Model, TransformExpression);
330335
else
331336
{

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace LinqToDB.EntityFrameworkCore
2828
using Metadata;
2929
using Extensions;
3030
using SqlQuery;
31+
using Reflection;
3132
using Common.Internal.Cache;
3233

3334
using DataProvider;
@@ -157,7 +158,7 @@ protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo provid
157158
case ProviderName.PostgreSQL:
158159
return CreatePostgreSqlProvider(PostgreSqlDefaultVersion, connectionInfo.ConnectionString);
159160
case ProviderName.SQLite:
160-
return new SQLiteDataProvider();
161+
return new SQLiteDataProvider(provInfo.ProviderName);
161162
case ProviderName.Firebird:
162163
return new FirebirdDataProvider();
163164
case ProviderName.DB2:
@@ -167,7 +168,7 @@ protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo provid
167168
case ProviderName.DB2zOS:
168169
return new DB2DataProvider(ProviderName.DB2, DB2Version.zOS);
169170
case ProviderName.Oracle:
170-
return new OracleDataProvider();
171+
return new OracleDataProvider(provInfo.ProviderName, OracleVersion.v11);
171172
case ProviderName.SqlCe:
172173
return new SqlCeDataProvider();
173174
//case ProviderName.Access:
@@ -293,12 +294,7 @@ protected virtual IDataProvider CreateSqlServerProvider(SqlServerVersion version
293294

294295
if (!string.IsNullOrEmpty(connectionString))
295296
{
296-
297-
if (typeof(DataConnection).Assembly.GetName().Version.Major >= 3)
298-
providerName = "Microsoft.Data.SqlClient";
299-
else
300-
//TODO: Remove after switching to linq2db 3.0
301-
providerName = "System.Data.SqlClient";
297+
providerName = "Microsoft.Data.SqlClient";
302298

303299
return DataConnection.GetDataProvider(providerName, connectionString);
304300
}
@@ -451,8 +447,8 @@ public virtual void DefineConvertors(
451447
Expression.New(DataParameterConstructor,
452448
Expression.Constant("Conv", typeof(string)),
453449
valueExpression,
454-
Expression.Constant(dataType.DataType, typeof(DataType)),
455-
Expression.Constant(dataType.DbType, typeof(string))
450+
Expression.Constant(dataType.Type.DataType, typeof(DataType)),
451+
Expression.Constant(dataType.Type.DbType, typeof(string))
456452
), fromParam);
457453

458454
mappingSchema.SetConvertExpression(clrType, typeof(DataParameter), convertLambda, false);
@@ -494,8 +490,6 @@ public virtual IDbContextOptions GetContextOptions(DbContext context)
494490
static readonly MethodInfo GetTableMethodInfo =
495491
MemberHelper.MethodOf<IDataContext>(dc => dc.GetTable<object>()).GetGenericMethodDefinition();
496492

497-
static readonly MethodInfo LoadWithMethodInfo = MemberHelper.MethodOf(() => LinqExtensions.LoadWith<int>(null, null)).GetGenericMethodDefinition();
498-
499493
static readonly MethodInfo WhereMethodInfo =
500494
MemberHelper.MethodOf<IQueryable<object>>(q => q.Where(p => true)).GetGenericMethodDefinition();
501495

@@ -752,14 +746,9 @@ Expression GetTableExpression(Type entityType)
752746

753747
if (memberExpression != param)
754748
{
755-
if (memberExpression.Type != typeof(object))
756-
{
757-
memberExpression = Expression.Convert(memberExpression, typeof(object));
758-
}
759-
760749
var loadWithLambda = Expression.Lambda(memberExpression, param);
761750

762-
newExpr = Expression.Call(null, LoadWithMethodInfo.MakeGenericMethod(entityType), newExpr,
751+
newExpr = Expression.Call(null, Methods.LinqToDB.LoadWith.MakeGenericMethod(entityType, memberExpression.Type), newExpr,
763752
Expression.Quote(loadWithLambda));
764753
}
765754
}

Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="linq2db" Version="2.9.6" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
12+
<PackageReference Include="linq2db" Version="3.0.0-preview.2" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
1414
</ItemGroup>
1515

1616
</Project>

Tests/LinqToDB.EntityFrameworkCore.Tests/LinqToDB.EntityFrameworkCore.Tests.csproj renamed to Tests/LinqToDB.EntityFrameworkCore.BaseTests/LinqToDB.EntityFrameworkCore.BaseTests.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.0.20171219.105559" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
18-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
15+
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
16+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.3" />
1917
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
20-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.1" />
2118
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
2219
<PrivateAssets>all</PrivateAssets>
2320
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2421
</PackageReference>
2522
<PackageReference Include="NUnit" Version="3.12.0" />
26-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
2723
</ItemGroup>
2824

2925
<ItemGroup>

Tests/LinqToDB.EntityFrameworkCore.Tests/Logging/LogMessageEntry.cs renamed to Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/LogMessageEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace LinqToDB.EntityFrameworkCore.Tests
3+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
44
{
55
internal readonly struct LogMessageEntry
66
{

Tests/LinqToDB.EntityFrameworkCore.Tests/Logging/NullExternalScopeProvider.cs renamed to Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/NullExternalScopeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using Microsoft.Extensions.Logging;
33

4-
namespace LinqToDB.EntityFrameworkCore.Tests
4+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
55
{
66
/// <summary>
77
/// Scope provider that does nothing.

Tests/LinqToDB.EntityFrameworkCore.Tests/Logging/NullScope.cs renamed to Tests/LinqToDB.EntityFrameworkCore.BaseTests/Logging/NullScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace LinqToDB.EntityFrameworkCore.Tests
3+
namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
44
{
55
internal class NullScope : IDisposable
66
{

0 commit comments

Comments
 (0)