.net 8 migration (#358)
* .net 8 migration * ci: install net8 sdk * fix ci * fix ci * update linq2db, ignore mysql exceptions from call translator * sqlite identity fix * mysql fix * update linq2db
This commit is contained in:
Родитель
ea431c333e
Коммит
bede9a6498
|
@ -5,6 +5,7 @@ indent_style = tab
|
|||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
end_of_line = crlf
|
||||
spelling_exclusion_path = spellcheck.txt
|
||||
|
||||
# Code files
|
||||
[*.{cs,csx,vb,vbx}]
|
||||
|
@ -160,15 +161,20 @@ dotnet_diagnostic.CA3076.severity = none # CA3076: Insecure XSLT Script Executio
|
|||
#########################################################################################################
|
||||
dotnet_diagnostic.CA1000.severity = none # CA1000: Do not declare static members on generic types
|
||||
dotnet_diagnostic.CA1001.severity = none # CA1001: Types that own disposable fields should be disposable
|
||||
dotnet_diagnostic.CA1002.severity = none # CA1002: Do not expose generic lists
|
||||
dotnet_diagnostic.CA1010.severity = none # CA1010: Collections should implement generic interface
|
||||
dotnet_diagnostic.CA1033.severity = none # CA1033: Interface methods should be callable by child types
|
||||
dotnet_diagnostic.CA1050.severity = none # CA1050: Declare types in namespaces
|
||||
dotnet_diagnostic.CA1036.severity = none # CA1036: Override methods on comparable types
|
||||
dotnet_diagnostic.CA1051.severity = none # CA1051: Do not declare visible instance fields
|
||||
dotnet_diagnostic.CA1056.severity = none # CA1056: URI properties should not be strings
|
||||
dotnet_diagnostic.CA1062.severity = none # CA1062: Validate arguments of public methods
|
||||
dotnet_diagnostic.CA1067.severity = none # CA1067: Override Equals when implementing IEquatable
|
||||
dotnet_diagnostic.CA1068.severity = none # CA1068: CancellationToken parameters must come last
|
||||
dotnet_diagnostic.CA1069.severity = none # CA1069: Enums should not have duplicate values
|
||||
dotnet_diagnostic.CA1304.severity = none # CA1304: Specify CultureInfo
|
||||
dotnet_diagnostic.CA1305.severity = none # CA1305: Specify IFormatProvider
|
||||
dotnet_diagnostic.CA1307.severity = none # CA1307: Specify StringComparison for clarity
|
||||
dotnet_diagnostic.CA1309.severity = none # CA1309: Use ordinal StringComparison
|
||||
dotnet_diagnostic.CA1310.severity = none # CA1310: Specify StringComparison for correctness
|
||||
dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores
|
||||
|
@ -178,8 +184,12 @@ dotnet_diagnostic.CA1715.severity = none # CA1715: Identifiers should have corre
|
|||
dotnet_diagnostic.CA1716.severity = none # CA1716: Identifiers should not match keywords
|
||||
dotnet_diagnostic.CA1720.severity = none # CA1720: Identifiers should not contain type names
|
||||
dotnet_diagnostic.CA1806.severity = none # CA1806: Do not ignore method results
|
||||
dotnet_diagnostic.CA1819.severity = none # CA1819: Properties should not return arrays
|
||||
dotnet_diagnostic.CA1822.severity = none # CA1822: Mark members as static
|
||||
dotnet_diagnostic.CA1859.severity = none # CA1859: Use concrete types when possible for improved performance
|
||||
dotnet_diagnostic.CA2211.severity = none # CA2211: Non-constant fields should not be visible
|
||||
dotnet_diagnostic.CA2225.severity = none # CA2225: Operator overloads have named alternates
|
||||
dotnet_diagnostic.CA2227.severity = none # CA2227: Remove property setter
|
||||
|
||||
###################################################################################
|
||||
# VS analyzers #
|
||||
|
@ -250,6 +260,8 @@ dotnet_diagnostic.IDE0080.severity = none # IDE0080: Remove unnecessary suppress
|
|||
dotnet_diagnostic.IDE0081.severity = none # IDE0081: Remove ByVal
|
||||
dotnet_diagnostic.IDE0083.severity = none # IDE0083: Use pattern matching (not operator)
|
||||
dotnet_diagnostic.IDE0130.severity = none # IDE0130: Namespace does not match folder structure
|
||||
dotnet_diagnostic.IDE0290.severity = none # IDE0290: Use primary constructor
|
||||
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Use collection expression (from ToArray)
|
||||
dotnet_diagnostic.IDE1006.severity = none # IDE1006: Naming rule violation
|
||||
|
||||
dotnet_diagnostic.CS1998.severity = error # CS1998: Async method lacks 'await' operators and will run synchronously
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Version>7.6.0</Version>
|
||||
<Version>8.0.0</Version>
|
||||
|
||||
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
|
||||
<Product>Linq to DB</Product>
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
|
||||
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -5,23 +5,21 @@
|
|||
<PackageVersion Include="NUnit" Version="3.13.3" />
|
||||
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
|
||||
|
||||
<PackageVersion Include="linq2db" Version="5.3.0" />
|
||||
<PackageVersion Include="linq2db.Tools" Version="5.3.0" />
|
||||
<PackageVersion Include="linq2db" Version="5.3.1" />
|
||||
<PackageVersion Include="linq2db.Tools" Version="5.3.1" />
|
||||
|
||||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
|
||||
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-rc.2.23480.1" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0-rc.2.23480.1" />
|
||||
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.2.23479.6" />
|
||||
|
||||
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="7.0.11" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
|
||||
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2.ci.20231014172607+sha.60ea450" />
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.0-rc.2" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-rc.2.23480.1" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-rc.2.23480.1" />
|
||||
|
||||
<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
|
||||
<PackageVersion Include="FSharp.Core" Version="7.0.400" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
10
NuGet.config
10
NuGet.config
|
@ -3,5 +3,15 @@
|
|||
<packageSources>
|
||||
<clear />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="pomelo-nightly" value="https://pkgs.dev.azure.com/pomelo-efcore/Pomelo.EntityFrameworkCore.MySql/_packaging/pomelo-efcore-public/nuget/v3/index.json" />
|
||||
<add key="linq2db" value="https://pkgs.dev.azure.com/linq2db/linq2db/_packaging/linq2db/nuget/v3/index.json" />
|
||||
</packageSources>
|
||||
<packageSourceMapping>
|
||||
<packageSource key="pomelo-nightly">
|
||||
<package pattern="Pomelo.EntityFrameworkCore.MySql" />
|
||||
</packageSource>
|
||||
<packageSource key="nuget.org">
|
||||
<package pattern="*" />
|
||||
</packageSource>
|
||||
</packageSourceMapping>
|
||||
</configuration>
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
<projectUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</projectUrl>
|
||||
<license type="file">MIT-LICENSE.txt</license>
|
||||
<dependencies>
|
||||
<group targetFramework="net6.0">
|
||||
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="7.0.0" />
|
||||
<dependency id="linq2db" version="5.3.0" />
|
||||
<group targetFramework="net8.0">
|
||||
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="8.0.0-rc.2.23480.1" />
|
||||
<dependency id="linq2db" version="5.3.1" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using LinqToDB.Common.Internal;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
@ -39,6 +40,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
private readonly IRelationalAnnotationProvider? _annotationProvider;
|
||||
private readonly ConcurrentDictionary<MemberInfo, EFCoreExpressionAttribute?> _calculatedExtensions = new();
|
||||
private readonly IDiagnosticsLogger<DbLoggerCategory.Query>? _logger;
|
||||
private readonly DatabaseDependencies? _databaseDependencies;
|
||||
|
||||
public EFCoreMetadataReader(IModel? model, IInfrastructure<IServiceProvider>? accessor)
|
||||
{
|
||||
|
@ -46,10 +48,11 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
if (accessor != null)
|
||||
{
|
||||
_dependencies = accessor.GetService<RelationalSqlTranslatingExpressionVisitorDependencies>();
|
||||
_mappingSource = accessor.GetService<IRelationalTypeMappingSource>();
|
||||
_annotationProvider = accessor.GetService<IRelationalAnnotationProvider>();
|
||||
_logger = accessor.GetService<IDiagnosticsLogger<DbLoggerCategory.Query>>();
|
||||
_dependencies = accessor.GetService<RelationalSqlTranslatingExpressionVisitorDependencies>();
|
||||
_mappingSource = accessor.GetService<IRelationalTypeMappingSource>();
|
||||
_annotationProvider = accessor.GetService<IRelationalAnnotationProvider>();
|
||||
_logger = accessor.GetService<IDiagnosticsLogger<DbLoggerCategory.Query>>();
|
||||
_databaseDependencies = accessor.GetService<DatabaseDependencies>();
|
||||
}
|
||||
|
||||
_objectId = $".{_model?.GetHashCode() ?? 0}.{_dependencies?.GetHashCode() ?? 0}.{_mappingSource?.GetHashCode() ?? 0}.{_annotationProvider?.GetHashCode() ?? 0}.{_logger?.GetHashCode() ?? 0}.";
|
||||
|
@ -124,10 +127,10 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
// TableAttribute
|
||||
var tableAttribute = type.GetAttribute<System.ComponentModel.DataAnnotations.Schema.TableAttribute>();
|
||||
if (tableAttribute != null)
|
||||
(result ??= new()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
|
||||
(result = new()).Add(new TableAttribute(tableAttribute.Name) { Schema = tableAttribute.Schema });
|
||||
}
|
||||
|
||||
return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
|
||||
return result == null ? [] : result.ToArray();
|
||||
}
|
||||
|
||||
static IEntityType GetBaseTypeRecursive(IEntityType entityType)
|
||||
|
@ -137,7 +140,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
return GetBaseTypeRecursive(entityType.BaseType);
|
||||
}
|
||||
|
||||
static IEnumerable<InheritanceMappingAttribute> GetMappingAttributesRecursive(IEntityType entityType)
|
||||
static List<InheritanceMappingAttribute> GetMappingAttributesRecursive(IEntityType entityType)
|
||||
{
|
||||
var mappings = new List<InheritanceMappingAttribute>();
|
||||
return ProcessEntityType(entityType);
|
||||
|
@ -221,7 +224,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public MappingAttribute[] GetAttributes(Type type, MemberInfo memberInfo)
|
||||
{
|
||||
if (typeof(Expression).IsSameOrParentOf(type))
|
||||
return Array.Empty<MappingAttribute>();
|
||||
return [];
|
||||
|
||||
List<MappingAttribute>? result = null;
|
||||
var hasColumn = false;
|
||||
|
@ -258,14 +261,30 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
var storeObjectId = GetStoreObjectIdentifier(et);
|
||||
|
||||
var isIdentity = false;
|
||||
var annotations = prop.GetAnnotations();
|
||||
if (_annotationProvider != null && storeObjectId != null)
|
||||
{
|
||||
if (prop.FindColumn(storeObjectId.Value) is IColumn column)
|
||||
annotations = annotations.Concat(_annotationProvider.For(column, false));
|
||||
|
||||
if (_annotationProvider.GetType().Name == "SqliteAnnotationProvider")
|
||||
{
|
||||
// copy-paste logic, not available anymore in v8
|
||||
// https://github.com/dotnet/efcore/blob/release/8.0/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs#L70-L75
|
||||
var primaryKey = prop.DeclaringType.ContainingEntityType.FindPrimaryKey();
|
||||
if (primaryKey is { Properties.Count: 1 }
|
||||
&& primaryKey.Properties[0] == prop
|
||||
&& prop.ValueGenerated == ValueGenerated.OnAdd
|
||||
&& prop.ClrType.IsInteger()
|
||||
&& prop.FindTypeMapping()?.Converter == null)
|
||||
{
|
||||
isIdentity = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isIdentity = annotations
|
||||
isIdentity = isIdentity || annotations
|
||||
.Any(static a =>
|
||||
{
|
||||
if (a.Name.EndsWith(":ValueGenerationStrategy"))
|
||||
|
@ -279,7 +298,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
{
|
||||
if (a.Value is string str)
|
||||
{
|
||||
return str.ToLowerInvariant().Contains("nextval");
|
||||
return str.Contains("nextval", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,15 +320,15 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
}
|
||||
}
|
||||
|
||||
var behaviour = prop.GetBeforeSaveBehavior();
|
||||
var behavior = prop.GetBeforeSaveBehavior();
|
||||
var skipOnInsert = prop.ValueGenerated.HasFlag(ValueGenerated.OnAdd);
|
||||
|
||||
if (skipOnInsert)
|
||||
{
|
||||
skipOnInsert = isIdentity || behaviour != PropertySaveBehavior.Save;
|
||||
skipOnInsert = isIdentity || behavior != PropertySaveBehavior.Save;
|
||||
}
|
||||
|
||||
var skipOnUpdate = behaviour != PropertySaveBehavior.Save ||
|
||||
var skipOnUpdate = behavior != PropertySaveBehavior.Save ||
|
||||
prop.ValueGenerated.HasFlag(ValueGenerated.OnUpdate);
|
||||
|
||||
var ca = new ColumnAttribute()
|
||||
|
@ -432,7 +451,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
});
|
||||
}
|
||||
|
||||
return result == null ? Array.Empty<MappingAttribute>() : result.ToArray();
|
||||
return result == null ? [] : result.ToArray();
|
||||
}
|
||||
|
||||
sealed class ValueConverter : IValueConverter
|
||||
|
@ -462,7 +481,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
protected override void Print(ExpressionPrinter expressionPrinter)
|
||||
{
|
||||
expressionPrinter.Print(Expression);
|
||||
expressionPrinter.PrintExpression(Expression);
|
||||
}
|
||||
|
||||
private bool Equals(SqlTransparentExpression other)
|
||||
|
@ -493,7 +512,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
};
|
||||
}
|
||||
|
||||
private Sql.ExpressionAttribute? GetDbFunctionFromMethodCall(Type type, MethodInfo methodInfo)
|
||||
private EFCoreExpressionAttribute? GetDbFunctionFromMethodCall(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
if (_dependencies == null || _model == null)
|
||||
return null;
|
||||
|
@ -516,8 +535,20 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
var p = parameterInfos[i];
|
||||
|
||||
parametersArray[i] = new SqlTransparentExpression(
|
||||
Expression.Constant(DefaultValue.GetValue(p.ParameterType), p.ParameterType),
|
||||
ctx.this_._mappingSource?.FindMapping(p.ParameterType));
|
||||
Expression.Constant(DefaultValue.GetValue(p.ParameterType), p.ParameterType),
|
||||
ctx.this_._mappingSource?.FindMapping(p.ParameterType));
|
||||
}
|
||||
|
||||
// https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1801
|
||||
if (ctx.this_._dependencies!.MethodCallTranslatorProvider.GetType().Name == "MySqlMethodCallTranslatorProvider")
|
||||
{
|
||||
var contextProperty = ctx.this_._dependencies!.MethodCallTranslatorProvider.GetType().GetProperty("QueryCompilationContext")
|
||||
?? throw new InvalidOperationException("MySqlMethodCallTranslatorProvider.QueryCompilationContext property not found");
|
||||
|
||||
if (contextProperty.GetValue(ctx.this_._dependencies!.MethodCallTranslatorProvider) == null)
|
||||
{
|
||||
contextProperty.SetValue(ctx.this_._dependencies!.MethodCallTranslatorProvider, ctx.this_._databaseDependencies!.QueryCompilationContextFactory.Create(false));
|
||||
}
|
||||
}
|
||||
|
||||
var newExpression = ctx.this_._dependencies!.MethodCallTranslatorProvider.Translate(ctx.this_._model!, objExpr, ctx.methodInfo, parametersArray, ctx.this_._logger!);
|
||||
|
@ -536,7 +567,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
return found;
|
||||
}
|
||||
|
||||
private Sql.ExpressionAttribute? GetDbFunctionFromProperty(Type type, PropertyInfo propInfo)
|
||||
private EFCoreExpressionAttribute? GetDbFunctionFromProperty(Type type, PropertyInfo propInfo)
|
||||
{
|
||||
if (_dependencies == null || _model == null)
|
||||
return null;
|
||||
|
@ -629,7 +660,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
// https://github.com/npgsql/efcore.pg/blob/main/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs
|
||||
if (newExpression.GetType().Name == "PostgresBinaryExpression")
|
||||
{
|
||||
// Handling NpgSql's PostgresBinaryExpression
|
||||
// Handling Npgsql PostgresBinaryExpression
|
||||
|
||||
var left = (Expression)newExpression.GetType().GetProperty("Left")!.GetValue(newExpression)!;
|
||||
var right = (Expression)newExpression.GetType().GetProperty("Right")!.GetValue(newExpression)!;
|
||||
|
@ -714,7 +745,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
public MemberInfo[] GetDynamicColumns(Type type)
|
||||
{
|
||||
return Array.Empty<MemberInfo>();
|
||||
return [];
|
||||
}
|
||||
|
||||
string IMetadataReader.GetObjectID() => _objectId;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace LinqToDB.EntityFrameworkCore.Internal
|
|||
/// <summary>
|
||||
/// Maps Linq To DB expression.
|
||||
/// </summary>
|
||||
public class EFCoreExpressionAttribute : Sql.ExpressionAttribute
|
||||
public sealed class EFCoreExpressionAttribute : Sql.ExpressionAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates instance of expression mapper.
|
||||
|
@ -42,20 +42,20 @@ namespace LinqToDB.EntityFrameworkCore.Internal
|
|||
knownExpressions.Add(me.Expression!);
|
||||
}
|
||||
|
||||
var parms = new List<ISqlExpression?>(knownExpressions.Select(_ => (ISqlExpression?) null));
|
||||
var @params = new List<ISqlExpression?>(knownExpressions.Select(_ => (ISqlExpression?) null));
|
||||
|
||||
_ = ResolveExpressionValues((context, parms, knownExpressions, converter), Expression!,
|
||||
_ = ResolveExpressionValues((context, @params, knownExpressions, converter), Expression!,
|
||||
static (ctx, v, d) =>
|
||||
{
|
||||
var idx = int.Parse(v);
|
||||
|
||||
if (ctx.parms[idx] == null)
|
||||
ctx.parms[idx] = ctx.converter(ctx.context, ctx.knownExpressions[idx], null);
|
||||
if (ctx.@params[idx] == null)
|
||||
ctx.@params[idx] = ctx.converter(ctx.context, ctx.knownExpressions[idx], null);
|
||||
|
||||
return v;
|
||||
});
|
||||
|
||||
var parameters = parms.Select(p => p ?? new SqlExpression("!!!")).ToArray();
|
||||
var parameters = @params.Select(p => p ?? new SqlExpression("!!!")).ToArray();
|
||||
return new SqlExpression(expression.Type, Expression!, Precedence, parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace LinqToDB.EntityFrameworkCore.Internal
|
|||
/// <param name="expression">Query expression.</param>
|
||||
public LinqToDBForEFQueryProvider(IDataContext dataContext, Expression expression)
|
||||
{
|
||||
if (expression == null) throw new ArgumentNullException(nameof(expression));
|
||||
ArgumentNullException.ThrowIfNull(expression);
|
||||
var dataContext1 = dataContext ?? throw new ArgumentNullException(nameof(dataContext));
|
||||
QueryProvider = (IQueryProviderAsync) Internals.CreateExpressionQueryInstance<T>(dataContext1, expression);
|
||||
QueryProviderAsQueryable = (IQueryable<T>) QueryProvider;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>Bulk insert operation status.</returns>
|
||||
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, BulkCopyOptions options, IEnumerable<T> source) where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>Bulk insert operation status.</returns>
|
||||
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, int maxBatchSize, IEnumerable<T> source) where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>Bulk insert operation status.</returns>
|
||||
public static BulkCopyRowsCopied BulkCopy<T>(this DbContext context, IEnumerable<T> source) where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -91,8 +91,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -117,11 +117,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -141,8 +138,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -164,8 +161,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -190,8 +187,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -211,8 +208,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
CancellationToken cancellationToken = default)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
|
||||
using (var dc = context.CreateLinqToDBConnection())
|
||||
{
|
||||
|
@ -236,10 +233,12 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> target)
|
||||
where T: notnull
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
if (target == null) throw new ArgumentNullException(nameof(target));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
ArgumentNullException.ThrowIfNull(target);
|
||||
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
return context.CreateLinqToDBConnection().Into(target);
|
||||
#pragma warning restore CA2000 // Dispose objects before losing scope
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -254,9 +253,11 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public static ITable<T> GetTable<T>(this DbContext context)
|
||||
where T : class
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
return context.CreateLinqToDBContext().GetTable<T>();
|
||||
#pragma warning restore CA2000 // Dispose objects before losing scope
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -270,7 +271,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public static DataOptions? GetLinqToDBOptions(this DbContext context)
|
||||
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
var contextOptions = ((IInfrastructure<IServiceProvider>)context.Database)?
|
||||
.Instance?.GetService(typeof(IDbContextOptions)) as IDbContextOptions;
|
||||
|
@ -284,9 +285,9 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>Db context options.</returns>
|
||||
public static DataOptions? GetLinqToDBOptions(this IDbContextOptions contextOptions)
|
||||
{
|
||||
if (contextOptions == null) throw new ArgumentNullException(nameof(contextOptions));
|
||||
ArgumentNullException.ThrowIfNull(contextOptions);
|
||||
|
||||
return contextOptions?.FindExtension<LinqToDBOptionsExtension>()?.Options;
|
||||
return contextOptions.FindExtension<LinqToDBOptionsExtension>()?.Options;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -15,7 +15,9 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
{
|
||||
var context = Implementation.GetCurrentContext(dbSet)
|
||||
?? throw new LinqToDBForEFToolsException($"Can not load current context from {nameof(dbSet)}");
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
var dc = CreateLinqToDBContext(context);
|
||||
#pragma warning restore CA2000 // Dispose objects before losing scope
|
||||
return dc.GetTable<T>();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initilaizes SQL Server's DbFunctions dynamically to avoid dependency
|
||||
/// Initializes SQL Server's DbFunctions dynamically to avoid dependency
|
||||
/// </summary>
|
||||
static void InitializeSqlServerMapping()
|
||||
{
|
||||
|
|
|
@ -33,14 +33,14 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
[PublicAPI]
|
||||
public static partial class LinqToDBForEFTools
|
||||
{
|
||||
static readonly Lazy<bool> _intialized = new(InitializeInternal);
|
||||
static readonly Lazy<bool> _initialized = new(InitializeInternal);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes integration of LINQ To DB with EF Core.
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
var _ = _intialized.Value;
|
||||
var _ = _initialized.Value;
|
||||
}
|
||||
|
||||
static bool InitializeInternal()
|
||||
|
@ -262,7 +262,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public static DataConnection CreateLinqToDBConnection(this DbContext context,
|
||||
IDbContextTransaction? transaction = null)
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
var info = GetEFProviderInfo(context);
|
||||
var options = context.GetLinqToDBOptions() ?? new DataOptions();
|
||||
|
@ -314,7 +314,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates logger intance.
|
||||
/// Creates logger instance.
|
||||
/// </summary>
|
||||
/// <param name="options"><see cref="DbContext" /> options.</param>
|
||||
/// <returns>Logger instance.</returns>
|
||||
|
@ -343,7 +343,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
public static IDataContext CreateLinqToDBContext(this DbContext context,
|
||||
IDbContextTransaction? transaction = null)
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
var info = GetEFProviderInfo(context);
|
||||
var options = context.GetLinqToDBOptions() ?? new DataOptions();
|
||||
|
@ -415,7 +415,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>LINQ To DB <see cref="DataConnection"/> instance.</returns>
|
||||
public static DataConnection CreateLinqToDBConnectionDetached(this DbContext context)
|
||||
{
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
var info = GetEFProviderInfo(context);
|
||||
var connectionInfo = GetConnectionInfo(info);
|
||||
|
@ -553,8 +553,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
/// <returns>LINQ To DB query, attached to provided <see cref="IDataContext"/>.</returns>
|
||||
public static IQueryable<T> ToLinqToDB<T>(this IQueryable<T> query, IDataContext dc)
|
||||
{
|
||||
if (query == null) throw new ArgumentNullException(nameof(query));
|
||||
if (dc == null) throw new ArgumentNullException(nameof(dc));
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
ArgumentNullException.ThrowIfNull(dc);
|
||||
|
||||
var context = Implementation.GetCurrentContext(query)
|
||||
?? throw new LinqToDBForEFToolsException("Can not evaluate current context from query");
|
||||
|
@ -590,7 +590,9 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
var context = Implementation.GetCurrentContext(query)
|
||||
?? throw new LinqToDBForEFToolsException("Can not evaluate current context from query");
|
||||
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
var dc = CreateLinqToDBContext(context);
|
||||
#pragma warning restore CA2000 // Dispose objects before losing scope
|
||||
|
||||
return new LinqToDBForEFQueryProvider<T>(dc, query.Expression);
|
||||
}
|
||||
|
|
|
@ -161,9 +161,9 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
//
|
||||
InternalEntityEntry? entry = null;
|
||||
|
||||
var kacheKey = new TypeKey (_lastEntityType, _model);
|
||||
var cacheKey = new TypeKey (_lastEntityType, _model);
|
||||
|
||||
var retrievalFunc = _entityKeyGetterCache.GetOrCreate(kacheKey, ce =>
|
||||
var retrievalFunc = _entityKeyGetterCache.GetOrCreate(cacheKey, ce =>
|
||||
{
|
||||
ce.SlidingExpiration = TimeSpan.FromHours(1);
|
||||
return CreateEntityRetrievalFunc(((TypeKey)ce.Key).EntityType);
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
/// <summary>
|
||||
/// Returns LINQ To DB provider, based on provider data from EF Core.
|
||||
/// Could be overriden if you have issues with default detection mechanisms.
|
||||
/// Could be overridden if you have issues with default detection mechanisms.
|
||||
/// </summary>
|
||||
/// <param name="options">Linq To DB context options.</param>
|
||||
/// <param name="providerInfo">Provider information, extracted from EF Core.</param>
|
||||
|
@ -438,8 +438,8 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
IValueConverterSelector? convertorSelector,
|
||||
DataOptions dataOptions)
|
||||
{
|
||||
if (mappingSchema == null) throw new ArgumentNullException(nameof(mappingSchema));
|
||||
if (model == null) throw new ArgumentNullException(nameof(model));
|
||||
ArgumentNullException.ThrowIfNull(mappingSchema);
|
||||
ArgumentNullException.ThrowIfNull(model);
|
||||
|
||||
if (convertorSelector == null)
|
||||
return;
|
||||
|
@ -805,7 +805,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
var tracking = true;
|
||||
var ignoreTracking = false;
|
||||
|
||||
var nonEvaluatableParameters = new HashSet<ParameterExpression>();
|
||||
var nonEvaluableParameters = new HashSet<ParameterExpression>();
|
||||
|
||||
TransformInfo LocalTransform(Expression e)
|
||||
{
|
||||
|
@ -817,7 +817,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
{
|
||||
foreach (var parameter in ((LambdaExpression)e).Parameters)
|
||||
{
|
||||
nonEvaluatableParameters.Add(parameter);
|
||||
nonEvaluableParameters.Add(parameter);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -890,7 +890,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
|
||||
var propName = (string)EvaluateExpression(methodCall.Arguments[1])!;
|
||||
var param = Expression.Parameter(methodCall.Method.GetGenericArguments()[0], "e");
|
||||
var propPath = propName.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
var propPath = propName.Split('.', StringSplitOptions.RemoveEmptyEntries);
|
||||
var prop = (Expression)param;
|
||||
for (int i = 0; i < propPath.Length; i++)
|
||||
{
|
||||
|
@ -962,7 +962,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
{
|
||||
if (((dc != null && !dc.MappingSchema.HasAttribute<ExpressionMethodAttribute>(methodCall.Type, methodCall.Method))
|
||||
|| (dc == null && !methodCall.Method.HasAttribute<ExpressionMethodAttribute>()))
|
||||
&& null == methodCall.Find(nonEvaluatableParameters,
|
||||
&& null == methodCall.Find(nonEvaluableParameters,
|
||||
(c, t) => t.NodeType == ExpressionType.Parameter && c.Contains(t) || t.NodeType == ExpressionType.Extension))
|
||||
{
|
||||
// Invoking function to evaluate EF's Subquery located in function
|
||||
|
@ -1146,7 +1146,7 @@ namespace LinqToDB.EntityFrameworkCore
|
|||
return expression;
|
||||
}
|
||||
|
||||
static Expression EnsureEnumerable(LambdaExpression lambda, MappingSchema mappingSchema)
|
||||
static LambdaExpression EnsureEnumerable(LambdaExpression lambda, MappingSchema mappingSchema)
|
||||
{
|
||||
var newBody = EnsureEnumerable(lambda.Body, mappingSchema);
|
||||
if (newBody != lambda.Body)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<Import Project="$(MSBuildThisFileDirectory)\..\Directory.Build.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -65,7 +65,6 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests
|
|||
|
||||
t.BulkCopy(items);
|
||||
|
||||
|
||||
items.Should().BeEquivalentTo(t);
|
||||
}
|
||||
|
||||
|
@ -129,7 +128,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests
|
|||
Assert.AreEqual(connection1.MappingSchema, connection2.MappingSchema);
|
||||
}
|
||||
|
||||
sealed class TestEntity
|
||||
protected sealed class TestEntity
|
||||
{
|
||||
public int Field { get; set; }
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="linq2db.Tools" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -2,26 +2,12 @@
|
|||
|
||||
namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
||||
{
|
||||
internal readonly struct LogMessageEntry
|
||||
{
|
||||
public LogMessageEntry(string message, string? timeStamp = null, string? levelString = null, ConsoleColor? levelBackground = null, ConsoleColor? levelForeground = null, ConsoleColor? messageColor = null, bool logAsError = false)
|
||||
{
|
||||
TimeStamp = timeStamp;
|
||||
LevelString = levelString;
|
||||
LevelBackground = levelBackground;
|
||||
LevelForeground = levelForeground;
|
||||
MessageColor = messageColor;
|
||||
Message = message;
|
||||
LogAsError = logAsError;
|
||||
}
|
||||
|
||||
public readonly string? TimeStamp;
|
||||
public readonly string? LevelString;
|
||||
public readonly ConsoleColor? LevelBackground;
|
||||
public readonly ConsoleColor? LevelForeground;
|
||||
public readonly ConsoleColor? MessageColor;
|
||||
public readonly string Message;
|
||||
public readonly bool LogAsError;
|
||||
}
|
||||
|
||||
internal readonly record struct LogMessageEntry(
|
||||
string Message,
|
||||
string? TimeStamp = null,
|
||||
string? LevelString = null,
|
||||
ConsoleColor? LevelBackground = null,
|
||||
ConsoleColor? LevelForeground = null,
|
||||
ConsoleColor? MessageColor = null,
|
||||
bool LogAsError = false);
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
{
|
||||
internal sealed class TestLogger : ILogger
|
||||
{
|
||||
private static readonly string _loglevelPadding = ": ";
|
||||
private static readonly string _messagePadding;
|
||||
private static readonly string _newLineWithMessagePadding;
|
||||
private const string _logLevelPadding = ": ";
|
||||
private static readonly string _messagePadding = new (' ', GetLogLevelString(LogLevel.Critical).Length + _logLevelPadding.Length);
|
||||
private static readonly string _newLineWithMessagePadding = Environment.NewLine + _messagePadding;
|
||||
|
||||
private readonly ConsoleColor DefaultConsoleColor = ConsoleColor.Black;
|
||||
|
||||
|
@ -19,13 +19,6 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
[ThreadStatic]
|
||||
private static StringBuilder? _logBuilder;
|
||||
|
||||
static TestLogger()
|
||||
{
|
||||
var logLevelString = GetLogLevelString(LogLevel.Information);
|
||||
_messagePadding = new string(' ', logLevelString.Length + _loglevelPadding.Length);
|
||||
_newLineWithMessagePadding = Environment.NewLine + _messagePadding;
|
||||
}
|
||||
|
||||
internal TestLogger(string name)
|
||||
{
|
||||
_name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
|
@ -42,10 +35,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
return;
|
||||
}
|
||||
|
||||
if (formatter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(formatter));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(formatter);
|
||||
|
||||
var message = formatter(state, exception);
|
||||
|
||||
|
@ -117,7 +107,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
var logLevelColors = GetLogLevelConsoleColors(logLevel);
|
||||
var logLevelString = GetLogLevelString(logLevel);
|
||||
// category and event id
|
||||
logBuilder.Append(_loglevelPadding)
|
||||
logBuilder.Append(_logLevelPadding)
|
||||
.Append(logName)
|
||||
.Append('[')
|
||||
.Append(eventId)
|
||||
|
@ -150,13 +140,13 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
return new LogMessageEntry(
|
||||
message: logBuilder.ToString(),
|
||||
timeStamp: timestampFormat != null ? DateTime.Now.ToString(timestampFormat) : null,
|
||||
levelString: logLevelString,
|
||||
levelBackground: logLevelColors.Background,
|
||||
levelForeground: logLevelColors.Foreground,
|
||||
messageColor: DefaultConsoleColor,
|
||||
logAsError: logLevel >= Options?.LogToStandardErrorThreshold
|
||||
Message: logBuilder.ToString(),
|
||||
TimeStamp: timestampFormat != null ? DateTime.Now.ToString(timestampFormat) : null,
|
||||
LevelString: logLevelString,
|
||||
LevelBackground: logLevelColors.Background,
|
||||
LevelForeground: logLevelColors.Foreground,
|
||||
MessageColor: DefaultConsoleColor,
|
||||
LogAsError: logLevel >= Options?.LogToStandardErrorThreshold
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -168,7 +158,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
// Example:
|
||||
// <6>ConsoleApp.Program[10] Request received
|
||||
|
||||
// loglevel
|
||||
// log level
|
||||
var logLevelString = GetSyslogSeverityString(logLevel);
|
||||
logBuilder.Append(logLevelString);
|
||||
|
||||
|
@ -210,8 +200,8 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
logBuilder.Append(Environment.NewLine);
|
||||
|
||||
return new LogMessageEntry(
|
||||
message: logBuilder.ToString(),
|
||||
logAsError: logLevel >= Options?.LogToStandardErrorThreshold
|
||||
Message: logBuilder.ToString(),
|
||||
LogAsError: logLevel >= Options?.LogToStandardErrorThreshold
|
||||
);
|
||||
|
||||
static void AppendAndReplaceNewLine(StringBuilder sb, string message)
|
||||
|
@ -236,9 +226,9 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
switch (logLevel)
|
||||
{
|
||||
case LogLevel.Trace:
|
||||
return "trce";
|
||||
return "trace";
|
||||
case LogLevel.Debug:
|
||||
return "dbug";
|
||||
return "debug";
|
||||
case LogLevel.Information:
|
||||
return "info";
|
||||
case LogLevel.Warning:
|
||||
|
@ -246,7 +236,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
case LogLevel.Error:
|
||||
return "fail";
|
||||
case LogLevel.Critical:
|
||||
return "crit";
|
||||
return "critical";
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(logLevel));
|
||||
}
|
||||
|
@ -314,9 +304,9 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
|
||||
scopeProvider.ForEachScope((scope, state) =>
|
||||
{
|
||||
var (builder, paddAt) = state;
|
||||
var padd = paddAt == builder.Length;
|
||||
if (padd)
|
||||
var (builder, paddingAt) = state;
|
||||
var addPadding = paddingAt == builder.Length;
|
||||
if (addPadding)
|
||||
{
|
||||
builder.Append(_messagePadding);
|
||||
builder.Append("=> ");
|
||||
|
@ -335,17 +325,6 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
}
|
||||
}
|
||||
|
||||
private readonly struct ConsoleColors
|
||||
{
|
||||
public ConsoleColors(ConsoleColor? foreground, ConsoleColor? background)
|
||||
{
|
||||
Foreground = foreground;
|
||||
Background = background;
|
||||
}
|
||||
|
||||
public ConsoleColor? Foreground { get; }
|
||||
|
||||
public ConsoleColor? Background { get; }
|
||||
}
|
||||
private readonly record struct ConsoleColors(ConsoleColor? Foreground, ConsoleColor? Background);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
/// <param name="configure">A delegate to configure the <see cref="ConsoleLogger"/>.</param>
|
||||
public static ILoggingBuilder AddTestLogger(this ILoggingBuilder builder, Action<ConsoleLoggerOptions> configure)
|
||||
{
|
||||
if (configure == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configure));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(configure);
|
||||
|
||||
builder.AddTestLogger();
|
||||
builder.Services.Configure(configure);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Logging
|
|||
/// A provider of <see cref="ConsoleLogger"/> instances.
|
||||
/// </summary>
|
||||
[ProviderAlias("Console")]
|
||||
public class TestLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
public sealed class TestLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
{
|
||||
private readonly IOptionsMonitor<ConsoleLoggerOptions> _options;
|
||||
private readonly ConcurrentDictionary<string, TestLogger> _loggers;
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.ForMapping
|
|||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string? AnsiString { get; set; }
|
||||
public string? AsciiString { get; set; }
|
||||
|
||||
public string? UnicodeString { get; set; }
|
||||
}
|
||||
|
|
|
@ -68,12 +68,6 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests.Models.Northwind
|
|||
orderDetail.Product = product;
|
||||
product.OrderDetails.Add(orderDetail);
|
||||
}
|
||||
|
||||
// foreach (var employee in _employees)
|
||||
// {
|
||||
// var manager = _employees.FirstOrDefault(e => employee.ReportsTo == e.EmployeeId);
|
||||
// employee.Manager = manager;
|
||||
// }
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> Set<TEntity>()
|
||||
|
|
|
@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging.Console;
|
|||
|
||||
namespace LinqToDB.EntityFrameworkCore.BaseTests
|
||||
{
|
||||
public class TestUtils
|
||||
public static class TestUtils
|
||||
{
|
||||
public static readonly ILoggerFactory LoggerFactory =
|
||||
Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
|
||||
|
|
|
@ -107,11 +107,11 @@ namespace LinqToDB.EntityFrameworkCore.BaseTests
|
|||
|
||||
for (var i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
var elist = expectedList[i].ToList();
|
||||
var rlist = resultList[i].ToList();
|
||||
var expectedElement = expectedList[i].ToList();
|
||||
var resultElement = resultList[i].ToList();
|
||||
|
||||
if (elist.Count > 0 || rlist.Count > 0)
|
||||
AreEqual(elist, rlist);
|
||||
if (expectedElement.Count > 0 || resultElement.Count > 0)
|
||||
AreEqual(expectedElement, resultElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
<ProjectReference Include="..\..\Source\LinqToDB.EntityFrameworkCore\linq2db.EntityFrameworkCore.csproj" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
|
||||
<PackageReference Include="EntityFrameworkCore.FSharp" />
|
||||
<PackageReference Include="FSharp.Core" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace LinqToDB.EntityFrameworkCore.PomeloMySql.Tests
|
|||
_options = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
private NorthwindContext CreateMySqlSqlExntitiesContext()
|
||||
private NorthwindContext CreateMySqlSqlEntitiesContext()
|
||||
{
|
||||
var ctx = new NorthwindContext(_options);
|
||||
ctx.Database.EnsureDeleted();
|
||||
|
@ -42,10 +42,25 @@ namespace LinqToDB.EntityFrameworkCore.PomeloMySql.Tests
|
|||
[Test]
|
||||
public void SimpleProviderTest()
|
||||
{
|
||||
using (var db = CreateMySqlSqlExntitiesContext())
|
||||
using (var db = CreateMySqlSqlEntitiesContext())
|
||||
{
|
||||
var items = db.Customers.Where(e => e.Address != null).ToLinqToDB().ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
[Test(Description = "https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1801")]
|
||||
public void TestFunctionTranslation()
|
||||
{
|
||||
using var db = CreateMySqlSqlEntitiesContext();
|
||||
var items = db.Customers.Where(e => e.Address!.Contains("anything")).ToLinqToDB().ToArray();
|
||||
}
|
||||
|
||||
[Test(Description = "https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1801")]
|
||||
public void TestFunctionTranslationParameter()
|
||||
{
|
||||
using var db = CreateMySqlSqlEntitiesContext();
|
||||
var value = "anything";
|
||||
var items = db.Customers.Where(e => e.Address!.Contains(value)).ToLinqToDB().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities
|
||||
{
|
||||
public class NpgSqlEnititesContext : DbContext
|
||||
{
|
||||
public NpgSqlEnititesContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Event>(entity =>
|
||||
entity.Property(e => e.Duration).HasColumnType("tsrange")
|
||||
);
|
||||
|
||||
modelBuilder.Entity<EventView>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
entity.ToView("EventsView", "views");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EntityWithArrays>(entity =>
|
||||
{
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EntityWithXmin>(entity =>
|
||||
{
|
||||
entity.Property<uint>(nameof(NpgSqlEntities.EntityWithXmin.xmin)).IsRowVersion();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TimeStampEntity>(e =>
|
||||
{
|
||||
e.Property(e => e.Timestamp1).HasColumnType("timestamp");
|
||||
e.Property(e => e.Timestamp2).HasColumnType("timestamp");
|
||||
e.Property(e => e.TimestampTZ1).HasColumnType("timestamp with time zone");
|
||||
e.Property(e => e.TimestampTZ2).HasColumnType("timestamp with time zone");
|
||||
e.Property(e => e.TimestampTZ3).HasColumnType("timestamp with time zone");
|
||||
});
|
||||
}
|
||||
|
||||
public virtual DbSet<Event> Events { get; set; } = null!;
|
||||
public virtual DbSet<EntityWithArrays> EntityWithArrays { get; set; } = null!;
|
||||
public virtual DbSet<EntityWithXmin> EntityWithXmin { get; set; } = null!;
|
||||
public virtual DbSet<TimeStampEntity> TimeStamps { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities
|
||||
{
|
||||
public class NpgSqlEntitiesContext : DbContext
|
||||
{
|
||||
public NpgSqlEntitiesContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Event>(entity =>
|
||||
entity.Property(e => e.Duration).HasColumnType("tsrange")
|
||||
);
|
||||
|
||||
modelBuilder.Entity<EventView>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
entity.ToView("EventsView", "views");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EntityWithArrays>(entity =>
|
||||
{
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EntityWithXmin>(entity =>
|
||||
{
|
||||
entity.Property<uint>(nameof(NpgSqlEntities.EntityWithXmin.xmin)).IsRowVersion();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TimeStampEntity>(e =>
|
||||
{
|
||||
e.Property(e => e.Timestamp1).HasColumnType("timestamp");
|
||||
e.Property(e => e.Timestamp2).HasColumnType("timestamp");
|
||||
e.Property(e => e.TimestampTZ1).HasColumnType("timestamp with time zone");
|
||||
e.Property(e => e.TimestampTZ2).HasColumnType("timestamp with time zone");
|
||||
e.Property(e => e.TimestampTZ3).HasColumnType("timestamp with time zone");
|
||||
});
|
||||
}
|
||||
|
||||
public virtual DbSet<Event> Events { get; set; } = null!;
|
||||
public virtual DbSet<EntityWithArrays> EntityWithArrays { get; set; } = null!;
|
||||
public virtual DbSet<EntityWithXmin> EntityWithXmin { get; set; } = null!;
|
||||
public virtual DbSet<TimeStampEntity> TimeStamps { get; set; } = null!;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests
|
|||
{
|
||||
public class NpgSqlTests : TestsBase
|
||||
{
|
||||
private DbContextOptions<NpgSqlEnititesContext> _options;
|
||||
private DbContextOptions<NpgSqlEntitiesContext> _options;
|
||||
|
||||
static NpgSqlTests()
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests
|
|||
|
||||
public NpgSqlTests()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NpgSqlEnititesContext>();
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NpgSqlEntitiesContext>();
|
||||
|
||||
//optionsBuilder.UseNpgsql("Server=DBHost;Port=5432;Database=TestData;User Id=postgres;Password=TestPassword;Pooling=true;MinPoolSize=10;MaxPoolSize=100;", o => o.UseNodaTime());
|
||||
optionsBuilder.UseNpgsql("Server=localhost;Port=5415;Database=TestData;User Id=postgres;Password=Password12!;Pooling=true;MinPoolSize=10;MaxPoolSize=100;", o => o.UseNodaTime());
|
||||
|
@ -32,9 +32,9 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests
|
|||
_options = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
private NpgSqlEnititesContext CreateNpgSqlEntitiesContext()
|
||||
private NpgSqlEntitiesContext CreateNpgSqlEntitiesContext()
|
||||
{
|
||||
var ctx = new NpgSqlEnititesContext(_options);
|
||||
var ctx = new NpgSqlEntitiesContext(_options);
|
||||
ctx.Database.EnsureDeleted();
|
||||
ctx.Database.EnsureCreated();
|
||||
ctx.Database.ExecuteSqlRaw("create schema \"views\"");
|
||||
|
|
|
@ -14,23 +14,24 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
|
||||
public static class AAA
|
||||
{
|
||||
public static ArrangeResult<T, Unit> Arrange<T>(this T @object, Action<T> action)
|
||||
internal static ArrangeResult<T, Unit> Arrange<T>(this T @object, Action<T> action)
|
||||
{
|
||||
action(@object);
|
||||
return new ArrangeResult<T, Unit>(@object, default);
|
||||
}
|
||||
|
||||
public static ArrangeResult<T, Unit> Arrange<T>(T @object)
|
||||
internal static ArrangeResult<T, Unit> Arrange<T>(T @object)
|
||||
=> new(@object, default);
|
||||
|
||||
public static ArrangeResult<T, TMock> Arrange<T, TMock>(this TMock mock, Func<TMock, T> @object)
|
||||
internal static ArrangeResult<T, TMock> Arrange<T, TMock>(this TMock mock, Func<TMock, T> @object)
|
||||
where TMock: notnull
|
||||
=> new(@object(mock), mock);
|
||||
|
||||
public static ActResult<T, TMock> Act<T, TMock>(this ArrangeResult<T, TMock> arrange, Action<T> act)
|
||||
internal static ActResult<T, TMock> Act<T, TMock>(this ArrangeResult<T, TMock> arrange, Action<T> act)
|
||||
where T : notnull
|
||||
where TMock : notnull
|
||||
{
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
try
|
||||
{
|
||||
act(arrange.Object);
|
||||
|
@ -40,12 +41,14 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
{
|
||||
return new ActResult<T, TMock>(arrange.Object, arrange.Mock, e);
|
||||
}
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
|
||||
public static ActResult<TResult, TMock> Act<T, TMock, TResult>(this ArrangeResult<T, TMock> arrange, Func<T, TResult> act)
|
||||
internal static ActResult<TResult, TMock> Act<T, TMock, TResult>(this ArrangeResult<T, TMock> arrange, Func<T, TResult> act)
|
||||
where TResult : notnull
|
||||
where TMock : notnull
|
||||
{
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
try
|
||||
{
|
||||
return new ActResult<TResult, TMock>(act(arrange.Object), arrange.Mock, default);
|
||||
|
@ -54,9 +57,10 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
{
|
||||
return new ActResult<TResult, TMock>(default, arrange.Mock, e);
|
||||
}
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
|
||||
public static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T?> assert)
|
||||
internal static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T?> assert)
|
||||
where T : notnull
|
||||
where TMock : notnull
|
||||
{
|
||||
|
@ -64,7 +68,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
assert(act.Object);
|
||||
}
|
||||
|
||||
public static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T?, TMock?> assert)
|
||||
internal static void Assert<T, TMock>(this ActResult<T, TMock> act, Action<T?, TMock?> assert)
|
||||
where T : notnull
|
||||
where TMock : notnull
|
||||
{
|
||||
|
@ -72,14 +76,15 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
assert(act.Object, act.Mock);
|
||||
}
|
||||
|
||||
public static Task<ArrangeResult<T, Unit>> ArrangeAsync<T>(T @object)
|
||||
internal static Task<ArrangeResult<T, Unit>> ArrangeAsync<T>(T @object)
|
||||
=> Task.FromResult(new ArrangeResult<T, Unit>(@object, default));
|
||||
|
||||
public static async Task<ActResult<TResult, TMock>> Act<T, TMock, TResult>(this Task<ArrangeResult<T, TMock>> arrange, Func<T, Task<TResult>> act)
|
||||
internal static async Task<ActResult<TResult, TMock>> Act<T, TMock, TResult>(this Task<ArrangeResult<T, TMock>> arrange, Func<T, Task<TResult>> act)
|
||||
where TMock : notnull
|
||||
where TResult : notnull
|
||||
{
|
||||
var a = await arrange;
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
try
|
||||
{
|
||||
return new ActResult<TResult, TMock>(await act(a.Object), a.Mock, default);
|
||||
|
@ -88,9 +93,10 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
{
|
||||
return new ActResult<TResult, TMock>(default, a.Mock, e);
|
||||
}
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
|
||||
public static async Task Assert<T, TMock>(this Task<ActResult<T, TMock>> act, Func<T?, Task> assert)
|
||||
internal static async Task Assert<T, TMock>(this Task<ActResult<T, TMock>> act, Func<T?, Task> assert)
|
||||
where T : notnull
|
||||
where TMock : notnull
|
||||
{
|
||||
|
@ -98,22 +104,10 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
await assert(result.Object);
|
||||
}
|
||||
|
||||
public readonly struct ArrangeResult<T, TMock>
|
||||
where TMock : notnull
|
||||
{
|
||||
internal ArrangeResult(T @object, TMock? mock) => (Object, Mock) = (@object, mock);
|
||||
internal T Object { get; }
|
||||
internal TMock? Mock { get; }
|
||||
}
|
||||
internal readonly record struct ArrangeResult<T, TMock>(T Object, TMock? Mock)
|
||||
where TMock : notnull;
|
||||
|
||||
public readonly struct ActResult<T, TMock>
|
||||
where T: notnull
|
||||
{
|
||||
internal ActResult(T? @object, TMock? mock, Exception? exception)
|
||||
=> (Object, Mock, Exception) = (@object, mock, exception);
|
||||
internal T? Object { get; }
|
||||
internal TMock? Mock { get; }
|
||||
internal Exception? Exception { get; }
|
||||
}
|
||||
internal readonly record struct ActResult<T, TMock>(T? Object, TMock? Mock, Exception? Exception)
|
||||
where T: notnull;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
=> new(id);
|
||||
}
|
||||
|
||||
public readonly struct Id<T, TId>
|
||||
public readonly struct Id<T, TId> : IEquatable<Id<T, TId>>
|
||||
where T : IHasId<T, TId>
|
||||
where TId : notnull
|
||||
{
|
||||
|
|
|
@ -42,23 +42,23 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
=> _efContext
|
||||
.Arrange(CreateLinqToDBContext)
|
||||
.Act(c => c.Insert(new Entity { Name = name }))
|
||||
.Assert(id => _efContext.Entitites.Single(e => e.Id == id).Name.Should().Be(name));
|
||||
.Assert(id => _efContext.Entities.Single(e => e.Id == id).Name.Should().Be(name));
|
||||
|
||||
[Test]
|
||||
[Ignore("Incomplete.")]
|
||||
public void TestInsertWithoutNew([Values("test insert")] string name)
|
||||
=> _efContext.Entitites
|
||||
=> _efContext.Entities
|
||||
.Arrange(e => e.ToLinqToDBTable())
|
||||
.Act(e => e.InsertWithInt64Identity(() => new Entity {Name = name}))
|
||||
.Assert(id => _efContext.Entitites.Single(e => e.Id == id).Name.Should().Be(name));
|
||||
.Assert(id => _efContext.Entities.Single(e => e.Id == id).Name.Should().Be(name));
|
||||
|
||||
[Test]
|
||||
[Ignore("Incomplete.")]
|
||||
public void TestInsertEfCore([Values("test insert ef")] string name)
|
||||
=> _efContext
|
||||
.Arrange(c => c.Entitites.Add(new Entity {Name = "test insert ef"}))
|
||||
.Arrange(c => c.Entities.Add(new Entity {Name = "test insert ef"}))
|
||||
.Act(_ => _efContext.SaveChanges())
|
||||
.Assert(_ => _efContext.Entitites.Single().Name.Should().Be(name));
|
||||
.Assert(_ => _efContext.Entities.Single().Name.Should().Be(name));
|
||||
|
||||
[Test]
|
||||
[Ignore("Incomplete.")]
|
||||
|
@ -66,7 +66,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
=> _efContext
|
||||
.Arrange(c => InsertDefaults(CreateLinqToDBContext(c)))
|
||||
.Act(c => c
|
||||
.Entitites
|
||||
.Entities
|
||||
.Where(e => e.Name == "Alpha")
|
||||
.Include(e => e.Details)
|
||||
.ThenInclude(d => d.Details)
|
||||
|
@ -82,7 +82,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
.Arrange(c => InsertDefaults(CreateLinqToDBContext(c)))
|
||||
.Act(c =>
|
||||
{
|
||||
var q = c.Entitites
|
||||
var q = c.Entities
|
||||
.Include(e => e.Items)
|
||||
.ThenInclude(x => x.Item);
|
||||
var f = q.AsLinqToDB(l2db).AsTracking().ToArray();
|
||||
|
@ -97,7 +97,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
public void TestManyToManyInclude([Values] bool l2db, [Values] bool tracking)
|
||||
=> _efContext
|
||||
.Arrange(c => InsertDefaults(CreateLinqToDBContext(c)))
|
||||
.Act(c => c.Entitites
|
||||
.Act(c => c.Entities
|
||||
.Include(e => e.Items)
|
||||
.ThenInclude(x => x.Item)
|
||||
.AsLinqToDB(l2db)
|
||||
|
@ -152,7 +152,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
dataContext.Insert(new Entity2Item {EntityId = b, ItemId = w});
|
||||
}
|
||||
|
||||
public class TestContext : DbContext
|
||||
private sealed class TestContext : DbContext
|
||||
{
|
||||
public TestContext(DbContextOptions options) : base(options) { }
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
@ -166,7 +166,7 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
}
|
||||
|
||||
|
||||
public DbSet<Entity> Entitites { get; set; } = null!;
|
||||
public DbSet<Entity> Entities { get; set; } = null!;
|
||||
public DbSet<Detail> Details { get; set; } = null!;
|
||||
public DbSet<SubDetail> SubDetails { get; set; } = null!;
|
||||
public DbSet<Item> Items { get; set; } = null!;
|
||||
|
|
|
@ -10,7 +10,9 @@ namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
|
|||
return input;
|
||||
|
||||
var startUnderscores = UnderscoresMatcher().Match(input);
|
||||
#pragma warning disable CA1308 // Normalize strings to uppercase
|
||||
return startUnderscores + Replacer().Replace(input, "$1_$2").ToLowerInvariant();
|
||||
#pragma warning restore CA1308 // Normalize strings to uppercase
|
||||
}
|
||||
|
||||
[GeneratedRegex("^_+")]
|
||||
|
|
|
@ -19,24 +19,19 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
private readonly DbContextOptions _northwindOptions;
|
||||
private readonly DbContextOptions _northwindOptionsWithEfCoreInterceptorsOnly;
|
||||
private DbConnection? _dbConnection;
|
||||
static TestCommandInterceptor _testCommandInterceptor;
|
||||
static TestDataContextInterceptor _testDataContextInterceptor;
|
||||
static TestConnectionInterceptor _testConnectionInterceptor;
|
||||
static TestEntityServiceInterceptor _testEntityServiceInterceptor;
|
||||
static TestEfCoreAndLinqToDBComboInterceptor _testEfCoreAndLinqToDBInterceptor;
|
||||
static TestCommandInterceptor _testCommandInterceptor = new();
|
||||
static TestDataContextInterceptor _testDataContextInterceptor = new();
|
||||
static TestConnectionInterceptor _testConnectionInterceptor = new();
|
||||
static TestEntityServiceInterceptor _testEntityServiceInterceptor = new();
|
||||
static TestEfCoreAndLinqToDBComboInterceptor _testEfCoreAndLinqToDBInterceptor = new();
|
||||
|
||||
static InterceptorTests()
|
||||
{
|
||||
_testCommandInterceptor = new TestCommandInterceptor();
|
||||
_testDataContextInterceptor = new TestDataContextInterceptor();
|
||||
_testConnectionInterceptor = new TestConnectionInterceptor();
|
||||
_testEntityServiceInterceptor = new TestEntityServiceInterceptor();
|
||||
_testEfCoreAndLinqToDBInterceptor = new TestEfCoreAndLinqToDBComboInterceptor();
|
||||
LinqToDBForEFTools.Initialize();
|
||||
DataConnection.TurnTraceSwitchOn();
|
||||
}
|
||||
|
||||
static DbContextOptions CreateNorthwindOptions()
|
||||
static DbContextOptions<NorthwindContext> CreateNorthwindOptions()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NorthwindContext>();
|
||||
optionsBuilder.UseSqlite(SQLITE_CONNECTION_STRING);
|
||||
|
@ -55,7 +50,7 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
return optionsBuilder.Options;
|
||||
}
|
||||
|
||||
static DbContextOptions CreateNorthwindOptionsWithEfCoreInterceptorsOnly()
|
||||
static DbContextOptions<NorthwindContext> CreateNorthwindOptionsWithEfCoreInterceptorsOnly()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NorthwindContext>();
|
||||
optionsBuilder.UseSqlite(SQLITE_CONNECTION_STRING);
|
||||
|
@ -78,7 +73,7 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
return ctx;
|
||||
}
|
||||
|
||||
private NorthwindContext CreateContextWithountLinqToDBExtensions()
|
||||
private NorthwindContext CreateContextWithoutLinqToDBExtensions()
|
||||
{
|
||||
var ctx = new NorthwindContext(_northwindOptionsWithEfCoreInterceptorsOnly);
|
||||
return ctx;
|
||||
|
@ -165,7 +160,7 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
[Test]
|
||||
public void TestEfCoreSideOfComboInterceptor()
|
||||
{
|
||||
using (var ctx = CreateContextWithountLinqToDBExtensions())
|
||||
using (var ctx = CreateContextWithoutLinqToDBExtensions())
|
||||
{
|
||||
var query =
|
||||
from pd in ctx.Products
|
||||
|
@ -180,7 +175,7 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
[Test]
|
||||
public void TestLinqToDBSideOfComboInterceptor()
|
||||
{
|
||||
using (var ctx = CreateContextWithountLinqToDBExtensions())
|
||||
using (var ctx = CreateContextWithoutLinqToDBExtensions())
|
||||
{
|
||||
var query =
|
||||
from pd in ctx.Products
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace LinqToDB.EntityFrameworkCore.SQLite.Tests
|
|||
_options = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
private NorthwindContext CreateSQLiteSqlExntitiesContext()
|
||||
private NorthwindContext CreateSQLiteSqlEntitiesContext()
|
||||
{
|
||||
var ctx = new NorthwindContext(_options);
|
||||
ctx.Database.EnsureDeleted();
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
var ms = LinqToDBForEFTools.GetMappingSchema(db.Model, db, null);
|
||||
var ed = ms.GetEntityDescriptor(typeof(StringTypes));
|
||||
|
||||
ed.Columns.First(c => c.MemberName == nameof(StringTypes.AnsiString)).DataType.Should()
|
||||
ed.Columns.First(c => c.MemberName == nameof(StringTypes.AsciiString)).DataType.Should()
|
||||
.Be(DataType.VarChar);
|
||||
|
||||
ed.Columns.First(c => c.MemberName == nameof(StringTypes.UnicodeString)).DataType.Should()
|
||||
|
|
|
@ -1,156 +1,156 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using LinqToDB.EntityFrameworkCore.BaseTests;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class JsonConverTests : TestsBase
|
||||
{
|
||||
private DbContextOptions<JsonConvertContext> _options;
|
||||
|
||||
public class LocalizedString
|
||||
{
|
||||
public string English { get; set; } = null!;
|
||||
public string German { get; set; } = null!;
|
||||
public string Slovak { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class EventScheduleItemBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public virtual LocalizedString NameLocalized { get; set; } = null!;
|
||||
public virtual string? JsonColumn { get; set; }
|
||||
}
|
||||
|
||||
public enum CrashEnum : byte
|
||||
{
|
||||
OneValue = 0,
|
||||
OtherValue = 1
|
||||
}
|
||||
|
||||
public class EventScheduleItem : EventScheduleItemBase
|
||||
{
|
||||
public CrashEnum CrashEnum { get; set; }
|
||||
public Guid GuidColumn { get; set; }
|
||||
}
|
||||
|
||||
public class JsonConvertContext : DbContext
|
||||
{
|
||||
public JsonConvertContext()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonConvertContext(DbContextOptions<JsonConvertContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual DbSet<EventScheduleItem> EventScheduleItems { get; set; } = null!;
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured) optionsBuilder.UseSqlServer("conn string");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<EventScheduleItem>(entity =>
|
||||
{
|
||||
entity.ToTable("EventScheduleItem");
|
||||
entity.Property(e => e.NameLocalized)
|
||||
.HasColumnName("NameLocalized_JSON")
|
||||
.HasConversion(v => JsonConvert.SerializeObject(v),
|
||||
v => JsonConvert.DeserializeObject<LocalizedString>(v) ?? new());
|
||||
entity.Property(e => e.CrashEnum).HasColumnType("tinyint");
|
||||
entity.Property(e => e.GuidColumn).HasColumnType("uniqueidentifier");
|
||||
});
|
||||
|
||||
modelBuilder.HasDbFunction(typeof(JsonConverTests).GetMethod(nameof(JsonConverTests.JsonValue))!)
|
||||
.HasTranslation(e => new SqlFunctionExpression(
|
||||
"JSON_VALUE", e, true, e.Select(_ => false), typeof(string), null));
|
||||
}
|
||||
}
|
||||
|
||||
public JsonConverTests()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<JsonConvertContext>();
|
||||
//new SqlServerDbContextOptionsBuilder(optionsBuilder);
|
||||
|
||||
optionsBuilder.UseSqlServer(Settings.JsonConvertConnectionString);
|
||||
optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory);
|
||||
|
||||
_options = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
public static string JsonValue(string? column, [NotParameterized] string path)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestJsonConvert()
|
||||
{
|
||||
LinqToDBForEFTools.Initialize();
|
||||
|
||||
// // converting from string, because usually JSON is stored as string, but it depends on DataProvider
|
||||
// Mapping.MappingSchema.Default.SetConverter<string, LocalizedString>(v => JsonConvert.DeserializeObject<LocalizedString>(v));
|
||||
//
|
||||
// // here we told linq2db how to pass converted value as DataParameter.
|
||||
// Mapping.MappingSchema.Default.SetConverter<LocalizedString, DataParameter>(v => new DataParameter("", JsonConvert.SerializeObject(v), LinqToDB.DataType.NVarChar));
|
||||
|
||||
using (var ctx = new JsonConvertContext(_options))
|
||||
{
|
||||
ctx.Database.EnsureDeleted();
|
||||
ctx.Database.EnsureCreated();
|
||||
|
||||
ctx.EventScheduleItems.Delete();
|
||||
|
||||
ctx.EventScheduleItems.Add(new EventScheduleItem()
|
||||
{
|
||||
NameLocalized = new LocalizedString() { English = "English", German = "German", Slovak = "Slovak" },
|
||||
GuidColumn = Guid.NewGuid()
|
||||
});
|
||||
ctx.SaveChanges();
|
||||
|
||||
var queryable = ctx.EventScheduleItems
|
||||
.Where(p => p.Id < 10).ToLinqToDB();
|
||||
|
||||
var path = "some";
|
||||
|
||||
var items = queryable
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.NameLocalized,
|
||||
p.CrashEnum,
|
||||
p.GuidColumn,
|
||||
JsonValue = JsonValue(p.JsonColumn, path)
|
||||
});
|
||||
|
||||
var item = items.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(item);
|
||||
Assert.That(item!.NameLocalized.English, Is.EqualTo("English"));
|
||||
Assert.That(item.NameLocalized.German, Is.EqualTo("German"));
|
||||
Assert.That(item.NameLocalized.Slovak, Is.EqualTo("Slovak"));
|
||||
|
||||
//TODO: make it work
|
||||
// var concrete = queryable.Select(p => new
|
||||
// {
|
||||
// p.Id,
|
||||
// English = p.NameLocalized.English
|
||||
// }).FirstOrDefault();
|
||||
//
|
||||
// Assert.That(concrete.English, Is.EqualTo("English"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using LinqToDB.EntityFrameworkCore.BaseTests;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class JsonConvertTests : TestsBase
|
||||
{
|
||||
private DbContextOptions<JsonConvertContext> _options;
|
||||
|
||||
private sealed class LocalizedString
|
||||
{
|
||||
public string English { get; set; } = null!;
|
||||
public string German { get; set; } = null!;
|
||||
public string Slovak { get; set; } = null!;
|
||||
}
|
||||
|
||||
private class EventScheduleItemBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public virtual LocalizedString NameLocalized { get; set; } = null!;
|
||||
public virtual string? JsonColumn { get; set; }
|
||||
}
|
||||
|
||||
#pragma warning disable CA1028 // Enum Storage should be Int32
|
||||
private enum CrashEnum : byte
|
||||
#pragma warning restore CA1028 // Enum Storage should be Int32
|
||||
{
|
||||
OneValue = 0,
|
||||
OtherValue = 1
|
||||
}
|
||||
|
||||
private sealed class EventScheduleItem : EventScheduleItemBase
|
||||
{
|
||||
public CrashEnum CrashEnum { get; set; }
|
||||
public Guid GuidColumn { get; set; }
|
||||
}
|
||||
|
||||
private sealed class JsonConvertContext : DbContext
|
||||
{
|
||||
public JsonConvertContext()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonConvertContext(DbContextOptions<JsonConvertContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<EventScheduleItem> EventScheduleItems { get; set; } = null!;
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured) optionsBuilder.UseSqlServer("conn string");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<EventScheduleItem>(entity =>
|
||||
{
|
||||
entity.ToTable("EventScheduleItem");
|
||||
entity.Property(e => e.NameLocalized)
|
||||
.HasColumnName("NameLocalized_JSON")
|
||||
.HasConversion(v => JsonConvert.SerializeObject(v),
|
||||
v => JsonConvert.DeserializeObject<LocalizedString>(v) ?? new());
|
||||
entity.Property(e => e.CrashEnum).HasColumnType("tinyint");
|
||||
entity.Property(e => e.GuidColumn).HasColumnType("uniqueidentifier");
|
||||
});
|
||||
|
||||
modelBuilder.HasDbFunction(typeof(JsonConvertTests).GetMethod(nameof(JsonValue))!)
|
||||
.HasTranslation(e => new SqlFunctionExpression(
|
||||
"JSON_VALUE", e, true, e.Select(_ => false), typeof(string), null));
|
||||
}
|
||||
}
|
||||
|
||||
public JsonConvertTests()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<JsonConvertContext>();
|
||||
//new SqlServerDbContextOptionsBuilder(optionsBuilder);
|
||||
|
||||
optionsBuilder.UseSqlServer(Settings.JsonConvertConnectionString);
|
||||
optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory);
|
||||
|
||||
_options = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
public static string JsonValue(string? column, [NotParameterized] string path)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestJsonConvert()
|
||||
{
|
||||
LinqToDBForEFTools.Initialize();
|
||||
|
||||
// // converting from string, because usually JSON is stored as string, but it depends on DataProvider
|
||||
// Mapping.MappingSchema.Default.SetConverter<string, LocalizedString>(v => JsonConvert.DeserializeObject<LocalizedString>(v));
|
||||
//
|
||||
// // here we told linq2db how to pass converted value as DataParameter.
|
||||
// Mapping.MappingSchema.Default.SetConverter<LocalizedString, DataParameter>(v => new DataParameter("", JsonConvert.SerializeObject(v), LinqToDB.DataType.NVarChar));
|
||||
|
||||
using (var ctx = new JsonConvertContext(_options))
|
||||
{
|
||||
ctx.Database.EnsureDeleted();
|
||||
ctx.Database.EnsureCreated();
|
||||
|
||||
ctx.EventScheduleItems.Delete();
|
||||
|
||||
ctx.EventScheduleItems.Add(new EventScheduleItem()
|
||||
{
|
||||
NameLocalized = new LocalizedString() { English = "English", German = "German", Slovak = "Slovak" },
|
||||
GuidColumn = Guid.NewGuid()
|
||||
});
|
||||
ctx.SaveChanges();
|
||||
|
||||
var queryable = ctx.EventScheduleItems
|
||||
.Where(p => p.Id < 10).ToLinqToDB();
|
||||
|
||||
var path = "some";
|
||||
|
||||
var items = queryable
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.NameLocalized,
|
||||
p.CrashEnum,
|
||||
p.GuidColumn,
|
||||
JsonValue = JsonValue(p.JsonColumn, path)
|
||||
});
|
||||
|
||||
var item = items.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(item);
|
||||
Assert.That(item!.NameLocalized.English, Is.EqualTo("English"));
|
||||
Assert.That(item.NameLocalized.German, Is.EqualTo("German"));
|
||||
Assert.That(item.NameLocalized.Slovak, Is.EqualTo("Slovak"));
|
||||
|
||||
//TODO: make it work
|
||||
// var concrete = queryable.Select(p => new
|
||||
// {
|
||||
// p.Id,
|
||||
// English = p.NameLocalized.English
|
||||
// }).FirstOrDefault();
|
||||
//
|
||||
// Assert.That(concrete.English, Is.EqualTo("English"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.ForMapping
|
|||
|
||||
modelBuilder.Entity<StringTypes>(b =>
|
||||
{
|
||||
b.Property(e => e.AnsiString).HasMaxLength(50).IsUnicode(false);
|
||||
b.Property(e => e.AsciiString).HasMaxLength(50).IsUnicode(false);
|
||||
b.Property(e => e.UnicodeString).HasMaxLength(50).IsUnicode();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.IssueModel
|
|||
.HasForeignKey(x => new { x.ParentId })
|
||||
.HasPrincipalKey(x => new { x.Id });
|
||||
|
||||
b.HasData(new[]
|
||||
{
|
||||
b.HasData(
|
||||
[
|
||||
new Issue73Entity
|
||||
{
|
||||
Id = 2,
|
||||
|
@ -36,7 +36,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.Models.IssueModel
|
|||
Name = "Name1_3",
|
||||
ParentId = 2
|
||||
},
|
||||
});
|
||||
]);
|
||||
});
|
||||
|
||||
modelBuilder
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
{
|
||||
public static class Settings
|
||||
{
|
||||
public static readonly string ForMappingConnectionString = "Server=.;Database=ForMapping;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public static readonly string IssuesConnectionString = "Server=.;Database=IssuesEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public static readonly string JsonConvertConnectionString = "Server=.;Database=JsonConvertContext;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public static readonly string NorthwindConnectionString = "Server=.;Database=NorthwindEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public static readonly string ConverterConnectionString = "Server=.;Database=ConverterTests;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public static readonly string InheritanceConnectionString = "Server=.;Database=InheritanceEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string ForMappingConnectionString = "Server=.;Database=ForMapping;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string IssuesConnectionString = "Server=.;Database=IssuesEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string JsonConvertConnectionString = "Server=.;Database=JsonConvertContext;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string NorthwindConnectionString = "Server=.;Database=NorthwindEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string ConverterConnectionString = "Server=.;Database=ConverterTests;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
public const string InheritanceConnectionString = "Server=.;Database=InheritanceEFCore;Integrated Security=SSPI;Encrypt=true;TrustServerCertificate=true";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
public class ToolsTests : TestsBase
|
||||
{
|
||||
private readonly DbContextOptions _options;
|
||||
private readonly DbContextOptions<NorthwindContext> _inmemoryOptions;
|
||||
private readonly DbContextOptions<NorthwindContext> _inMemoryOptions;
|
||||
|
||||
static ToolsTests()
|
||||
{
|
||||
|
@ -42,12 +42,12 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
optionsBuilder.UseInMemoryDatabase("sample");
|
||||
optionsBuilder.UseLoggerFactory(TestUtils.LoggerFactory);
|
||||
|
||||
_inmemoryOptions = optionsBuilder.Options;
|
||||
_inMemoryOptions = optionsBuilder.Options;
|
||||
}
|
||||
|
||||
private NorthwindContext CreateContextInMemory()
|
||||
{
|
||||
var ctx = new NorthwindContext(_inmemoryOptions);
|
||||
var ctx = new NorthwindContext(_inMemoryOptions);
|
||||
ctx.Database.EnsureCreated();
|
||||
return ctx;
|
||||
}
|
||||
|
@ -55,14 +55,16 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
private void SetIdentityInsert(DbContext ctx, string tableName, bool isOn)
|
||||
{
|
||||
var str = $"SET IDENTITY_INSERT {tableName} " + (isOn ? "ON" : "OFF");
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
try
|
||||
{
|
||||
ctx.Database.ExecuteSqlRaw(str);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
// swallow
|
||||
}
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
|
||||
private NorthwindContext CreateContext(bool enableFilter)
|
||||
|
@ -77,14 +79,6 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
return ctx;
|
||||
}
|
||||
|
||||
public class VwProductAndDescription
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public string ProductModel { get; set; } = null!;
|
||||
public string Description { get; set; } = null!;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToList([Values(true, false)] bool enableFilter)
|
||||
{
|
||||
|
@ -122,8 +116,10 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
{
|
||||
using (var ctx = CreateContext(enableFilter))
|
||||
{
|
||||
#pragma warning disable CA1866 // Use char overload
|
||||
var query = ProductQuery(ctx)
|
||||
.Where(pd => pd.ProductName.StartsWith("a"));
|
||||
#pragma warning restore CA1866 // Use char overload
|
||||
|
||||
query.Where(p => p.ProductName == "a").Delete();
|
||||
}
|
||||
|
@ -135,9 +131,11 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
{
|
||||
using (var ctx = CreateContext(enableFilter))
|
||||
{
|
||||
#pragma warning disable CA1866 // Use char overload
|
||||
var query = ProductQuery(ctx)
|
||||
.ToLinqToDB()
|
||||
.Where(pd => pd.ProductName.StartsWith("a"));
|
||||
#pragma warning restore CA1866 // Use char overload
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,8 +144,10 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
{
|
||||
using (var ctx = CreateContext(enableFilter))
|
||||
{
|
||||
#pragma warning disable CA1866 // Use char overload
|
||||
var query = ProductQuery(ctx)
|
||||
.Where(pd => pd.ProductName.StartsWith("a"));
|
||||
#pragma warning restore CA1866 // Use char overload
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,12 +215,14 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
{
|
||||
using (var ctx = CreateContext(enableFilter))
|
||||
{
|
||||
using (var transaction = ctx.Database.BeginTransaction())
|
||||
await using (var transaction = await ctx.Database.BeginTransactionAsync())
|
||||
using (var db = ctx.CreateLinqToDBConnection())
|
||||
{
|
||||
|
||||
#pragma warning disable CA1866 // Use char overload
|
||||
var test1 = await ctx.Products.Where(p => p.ProductName.StartsWith("U")).MaxAsync(p => p.QuantityPerUnit);
|
||||
var test2 = await ctx.Products.Where(p => p.ProductName.StartsWith("U")).MaxAsyncLinqToDB(p => p.QuantityPerUnit);
|
||||
#pragma warning restore CA1866 // Use char overload
|
||||
|
||||
Assert.AreEqual(test1, test2);
|
||||
|
||||
|
@ -228,7 +230,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
.ToLinqToDB(db)
|
||||
.Delete();
|
||||
|
||||
transaction.Rollback();
|
||||
await transaction.RollbackAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +241,11 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
using (var ctx = CreateContext(enableFilter))
|
||||
using (var db = ctx.CreateLinqToDBConnection())
|
||||
{
|
||||
#pragma warning disable CA1866 // Use char overload
|
||||
var query = ProductQuery(ctx)
|
||||
.ToLinqToDB(db)
|
||||
.Where(pd => pd.ProductName.StartsWith("a"));
|
||||
#pragma warning restore CA1866 // Use char overload
|
||||
|
||||
var items = query.ToArray();
|
||||
}
|
||||
|
@ -534,7 +538,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
|
||||
ctx.ChangeTracker.DetectChanges();
|
||||
var changedEntry = ctx.ChangeTracker.Entries().Single(e => e.State == EntityState.Modified);
|
||||
ctx.SaveChanges();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -558,7 +562,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
ctx.ChangeTracker.DetectChanges();
|
||||
var changedEntry = ctx.ChangeTracker.Entries().SingleOrDefault(e => e.State == EntityState.Modified);
|
||||
Assert.AreEqual(changedEntry, null);
|
||||
ctx.SaveChanges();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -584,7 +588,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
ctx.ChangeTracker.DetectChanges();
|
||||
var changedEntry = ctx.ChangeTracker.Entries().SingleOrDefault(e => e.State == EntityState.Modified);
|
||||
Assert.AreEqual(changedEntry, null);
|
||||
ctx.SaveChanges();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -867,7 +871,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
|
|||
}
|
||||
}
|
||||
|
||||
static DbContextOptions CreateInheritanceOptions()
|
||||
static DbContextOptions<InheritanceContext> CreateInheritanceOptions()
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<InheritanceContext>();
|
||||
|
||||
|
|
|
@ -13,14 +13,14 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.ValueConversion
|
|||
{
|
||||
private DbContextOptions<ConvertorContext> _options;
|
||||
|
||||
public class ConvertorContext : DbContext
|
||||
private sealed class ConvertorContext : DbContext
|
||||
{
|
||||
public ConvertorContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public virtual DbSet<SubDivision> Subdivisions { get; set; } = null!;
|
||||
public DbSet<SubDivision> Subdivisions { get; set; } = null!;
|
||||
}
|
||||
|
||||
public ConvertorTests()
|
||||
|
@ -46,32 +46,31 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests.ValueConversion
|
|||
ctx.Database.EnsureCreated();
|
||||
|
||||
|
||||
var resut = db.InsertWithInt64Identity(new SubDivision()
|
||||
var result = db.InsertWithInt64Identity(new SubDivision()
|
||||
{ Code = "C1", Id = new Id<SubDivision, long>(0), Name = "N1", PermanentId = Guid.NewGuid() });
|
||||
|
||||
resut = db.InsertWithInt64Identity(new SubDivision()
|
||||
result = db.InsertWithInt64Identity(new SubDivision()
|
||||
{ Code = "C2", Id = new Id<SubDivision, long>(1), Name = "N2", PermanentId = Guid.NewGuid() });
|
||||
|
||||
resut = db.InsertWithInt64Identity(new SubDivision()
|
||||
result = db.InsertWithInt64Identity(new SubDivision()
|
||||
{ Code = "C3", Id = new Id<SubDivision, long>(2), Name = "N3", PermanentId = Guid.NewGuid() });
|
||||
|
||||
var ef = ctx.Subdivisions.Where(s => s.Id == 1L).ToArray();
|
||||
var ltdb = ctx.Subdivisions.ToLinqToDB().Where(s => s.Id == 1L).ToArray();
|
||||
var result1 = ctx.Subdivisions.ToLinqToDB().Where(s => s.Id == 1L).ToArray();
|
||||
|
||||
var id = new Id<SubDivision, long>?(0L.AsId<SubDivision>());
|
||||
var ltdb2 = ctx.Subdivisions.ToLinqToDB().Where(s => s.Id == id).ToArray();
|
||||
var result2 = ctx.Subdivisions.ToLinqToDB().Where(s => s.Id == id).ToArray();
|
||||
|
||||
var ids = new[] {1L.AsId<SubDivision>(), 2L.AsId<SubDivision>(),};
|
||||
var ltdbin = ctx.Subdivisions.ToLinqToDB()
|
||||
.Where(s => ids.Contains(s.Id)).ToArray();
|
||||
_ = ctx.Subdivisions.ToLinqToDB().Where(s => ids.Contains(s.Id)).ToArray();
|
||||
|
||||
var all = ctx.Subdivisions.ToLinqToDB().ToArray();
|
||||
_ = ctx.Subdivisions.ToLinqToDB().ToArray();
|
||||
|
||||
Assert.AreEqual(ef[0].Code, ltdb[0].Code);
|
||||
Assert.AreEqual(ef[0].Id, ltdb[0].Id);
|
||||
Assert.AreEqual(ef[0].Code, result1[0].Code);
|
||||
Assert.AreEqual(ef[0].Id, result1[0].Id);
|
||||
|
||||
Assert.AreEqual(ef[0].Code, ltdb2[0].Code);
|
||||
Assert.AreEqual(ef[0].Id, ltdb2[0].Id);
|
||||
Assert.AreEqual(ef[0].Code, result2[0].Code);
|
||||
Assert.AreEqual(ef[0].Id, result2[0].Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
variables:
|
||||
solution: 'linq2db.EFCore.sln'
|
||||
build_configuration: 'Release'
|
||||
assemblyVersion: 7.6.0
|
||||
nugetVersion: 7.6.0
|
||||
assemblyVersion: 8.0.0
|
||||
nugetVersion: 8.0.0-rc.2
|
||||
artifact_nugets: 'nugets'
|
||||
|
||||
# build on commits to important branches (master + release branches):
|
||||
|
@ -32,6 +32,13 @@ stages:
|
|||
|
||||
steps:
|
||||
|
||||
|
||||
- task: UseDotNet@2
|
||||
displayName: 'Install .NET 8'
|
||||
inputs:
|
||||
includePreviewVersions: true
|
||||
version: 8.x
|
||||
|
||||
- task: PowerShell@2
|
||||
inputs:
|
||||
filePath: '$(Build.SourcesDirectory)/Build/SetVersion.ps1'
|
||||
|
@ -39,11 +46,12 @@ stages:
|
|||
arguments: -path $(Build.SourcesDirectory)/Directory.Build.props -version $(assemblyVersion)
|
||||
displayName: Update assembly version
|
||||
|
||||
- task: MSBuild@1
|
||||
- task: DotNetCoreCLI@2
|
||||
inputs:
|
||||
solution: '$(solution)'
|
||||
command: 'build'
|
||||
projects: '$(solution)'
|
||||
configuration: '$(build_configuration)'
|
||||
msbuildArguments: '/t:Restore;Rebuild -m /p:ContinuousIntegrationBuild=true'
|
||||
arguments: '-property:ContinuousIntegrationBuild=true'
|
||||
displayName: Build Solution
|
||||
|
||||
- powershell: echo "##vso[task.setvariable variable=packageVersion]$(packageVersion)-rc.$(Build.BuildId)"
|
||||
|
|
|
@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{A3F30061
|
|||
Directory.Packages.props = Directory.Packages.props
|
||||
Build\linq2db.snk = Build\linq2db.snk
|
||||
Build\SetVersion.ps1 = Build\SetVersion.ps1
|
||||
spellcheck.txt = spellcheck.txt
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7316BE20-8825-4234-923D-45F0FBC48B7D}"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
Impl
|
||||
Devart
|
||||
Postgre
|
||||
Npgsql
|
||||
Sqlite
|
||||
enums
|
||||
infos
|
||||
param
|
||||
Insertable
|
||||
instantiator
|
||||
params
|
||||
postgres
|
||||
nextval
|
||||
Cidr
|
||||
Inet
|
||||
getutcdate
|
||||
datediff
|
||||
Systemd
|
||||
Utils
|
||||
Desc
|
||||
Unnest
|
||||
xmin
|
||||
tsrange
|
||||
northwind
|
||||
nvarchar
|
||||
uniqueidentifier
|
||||
tinyint
|
||||
Deserialize
|
||||
varbinary
|
||||
mysql
|
Загрузка…
Ссылка в новой задаче