Skip to content

Commit d3a203b

Browse files
committed
Merge branch 'net-core-31' into async-enumerable-1
# Conflicts: # Extensions/Xtensive.Orm.BulkOperations.Tests/Other.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/ExpressionExtensions.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/QueryOperation.cs # Extensions/Xtensive.Orm.BulkOperations/Internals/SetOperation.cs # Extensions/Xtensive.Orm.Web/ApplicationBuilderExtensions.cs # Orm/Xtensive.Orm.Firebird/Sql.Drivers.Firebird/Connection.cs # Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/Connection.cs # Orm/Xtensive.Orm.Oracle/Sql.Drivers.Oracle/Connection.cs # Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/Connection.cs # Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/DriverFactory.cs # Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/Connection.cs # Orm/Xtensive.Orm.Sqlite/Sql.Drivers.Sqlite/Connection.cs # Orm/Xtensive.Orm.Tests/Storage/SessionEventsTest.cs # Orm/Xtensive.Orm/Orm/Linq/Expressions/ItemProjectorExpression.cs # Orm/Xtensive.Orm/Orm/Linq/Materialization/ExpressionMaterializer.cs # Orm/Xtensive.Orm/Orm/Linq/QueryHelper.cs # Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs # Orm/Xtensive.Orm/Orm/Linq/Translator.Queryable.cs # Orm/Xtensive.Orm/Orm/Providers/SqlCompiler.cs # Orm/Xtensive.Orm/Sql/SqlConnection.cs
2 parents 24ae19d + a5b6abf commit d3a203b

91 files changed

Lines changed: 2551 additions & 890 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ _Build
2626
_Work
2727
.vs
2828
.idea
29-
User.Directory.Build.props
29+
User.Directory.Build.props

Directory.Build.props

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</PropertyGroup>
2323

2424
<PropertyGroup>
25-
<LangVersion>8.0</LangVersion>
25+
<TargetFramework>netcoreapp3.1</TargetFramework>
2626
<SolutionDir Condition="$(SolutionDir) == ''">$(MSBuildThisFileDirectory.TrimEnd('\').TrimEnd('/'))\</SolutionDir>
2727
<Configuration Condition="$(Configuration) == ''">Debug</Configuration>
2828
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
@@ -36,6 +36,7 @@
3636
<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath>
3737
<ProjectAssetsFile>$(MSBuildProjectExtensionsPath)project.assets.json</ProjectAssetsFile>
3838
<ProjectAssetsCacheFile>$(MSBuildProjectExtensionsPath)$(MSBuildProjectName).assets.cache</ProjectAssetsCacheFile>
39+
<OrmKeyFile>$(SolutionDir)Orm\Orm.snk</OrmKeyFile>
3940
</PropertyGroup>
4041

4142
<PropertyGroup>
@@ -59,14 +60,20 @@
5960
<PackageIcon>do-nuget.png</PackageIcon>
6061
<PackageLicense>Apache-2.0</PackageLicense>
6162
<PackageTags>DataObjects.Net ORM BLL Persistence</PackageTags>
62-
<PackageOutputPath>$(MSBuildThisFileDirectory)_Build\$(Configuration)\packages</PackageOutputPath>
63+
<PackageOutputPath>$(MSBuildThisFileDirectory)_Build\$(Configuration)\packages\</PackageOutputPath>
6364
<RepositoryUrl>https://github.com/DataObjects-NET/dataobjects-net</RepositoryUrl>
6465
<RepositoryType>git</RepositoryType>
6566
</PropertyGroup>
6667

6768
<ItemGroup>
68-
<None Include="$(DoPackageIcon)" Pack="true" PackagePath="." Visible="false" />
69-
<None Include="$(DoRevFile)" Pack="true" PackagePath="." Visible="false" Condition="Exists('$(DoRevFile)')" />
69+
<None Include="$(DoPackageIcon)" Visible="false" >
70+
<PackagePath>.</PackagePath>
71+
<Pack>true</Pack>
72+
</None>
73+
<None Include="$(DoRevFile)" Visible="false" Condition="Exists('$(DoRevFile)')" >
74+
<PackagePath>.</PackagePath>
75+
<Pack>true</Pack>
76+
</None>
7077
</ItemGroup>
7178
<Target Name="ExportRev" Condition="Exists('.git\index') AND '$(Configuration)' == 'Release'">
7279
<MakeDir Directories="_Build" />

Extensions/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(SolutionDir)Directory.Build.props" />
4+
<PropertyGroup>
5+
<ExtensionsKeyFile>$(MSBuildThisFileDirectory)Extensions.snk</ExtensionsKeyFile>
6+
</PropertyGroup>
7+
</Project>

Extensions/TestCommon/TestCommon.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputPath>..\..\_Build\$(Configuration)\lib\</OutputPath>
3+
<OutputPath>$(SolutionDir)_Build\$(Configuration)\lib\</OutputPath>
44
<DocumentationFile />
55
</PropertyGroup>
66
<PropertyGroup>
7-
<TargetFramework>netcoreapp3.1</TargetFramework>
87
<SignAssembly>true</SignAssembly>
9-
<AssemblyOriginatorKeyFile>..\Extensions.snk</AssemblyOriginatorKeyFile>
8+
<AssemblyOriginatorKeyFile>$(ExtensionsKeyFile)</AssemblyOriginatorKeyFile>
109
</PropertyGroup>
11-
<Import Project="..\..\MSBuild\DataObjects.Net.InternalBuild.targets" />
10+
<Import Project="$(SolutionDir)MSBuild\DataObjects.Net.InternalBuild.targets" />
1211
<ItemGroup>
1312
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.2" />
1413
<PackageReference Include="NUnit" Version="3.12.0" />
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (C) 2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Linq;
7+
using NUnit.Framework;
8+
using Xtensive.Orm.BulkOperations.ContainsTestModel;
9+
using Xtensive.Orm.Configuration;
10+
11+
namespace Xtensive.Orm.BulkOperations.ContainsTestModel
12+
{
13+
[HierarchyRoot]
14+
[KeyGenerator(KeyGeneratorKind.None)]
15+
public class TagType : Entity
16+
{
17+
[Field, Key]
18+
public long Id { get; private set; }
19+
20+
[Field]
21+
public int ProjectedValueAdjustment { get; set; }
22+
23+
public TagType(Session session, long id)
24+
:base(session, id)
25+
{
26+
}
27+
}
28+
}
29+
30+
namespace Xtensive.Orm.BulkOperations.Tests
31+
{
32+
public class ContainsTest : AutoBuildTest
33+
{
34+
private long[] tagIds;
35+
36+
protected override DomainConfiguration BuildConfiguration()
37+
{
38+
var configuration = base.BuildConfiguration();
39+
configuration.Types.Register(typeof(TagType).Assembly, typeof(TagType).Namespace);
40+
return configuration;
41+
}
42+
43+
protected override void PopulateData()
44+
{
45+
tagIds = Enumerable.Range(0, 100).Select(i => (long) i).ToArray();
46+
using (var session = Domain.OpenSession())
47+
using (var transaction = session.OpenTransaction()) {
48+
foreach (var id in tagIds.Concat(Enumerable.Repeat(1000, 1).Select(i => (long) i)))
49+
new TagType(session, id) { ProjectedValueAdjustment = -1 };
50+
transaction.Complete();
51+
}
52+
}
53+
54+
[Test]
55+
public void Test1()
56+
{
57+
using (var session = Domain.OpenSession())
58+
using (var tx = session.OpenTransaction()) {
59+
var updatedRows = session.Query.All<TagType>()
60+
.Where(t => t.Id.In(tagIds))
61+
.Set(t => t.ProjectedValueAdjustment, 2)
62+
.Update();
63+
Assert.That(updatedRows, Is.EqualTo(100));
64+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == 2 && t.Id <= 200), Is.EqualTo(100));
65+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == -1 && t.Id > 700), Is.EqualTo(1));
66+
}
67+
}
68+
69+
[Test]
70+
public void Test2()
71+
{
72+
using (var session = Domain.OpenSession())
73+
using (var tx = session.OpenTransaction()) {
74+
var updatedRows = session.Query.All<TagType>()
75+
.Where(t => t.Id.In(IncludeAlgorithm.ComplexCondition, tagIds))
76+
.Set(t => t.ProjectedValueAdjustment, 2)
77+
.Update();
78+
Assert.That(updatedRows, Is.EqualTo(100));
79+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == 2 && t.Id <= 200), Is.EqualTo(100));
80+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == -1 && t.Id > 700), Is.EqualTo(1));
81+
}
82+
}
83+
84+
[Test]
85+
public void Test3()
86+
{
87+
using (var session = Domain.OpenSession())
88+
using (var tx = session.OpenTransaction()) {
89+
Assert.Throws<NotSupportedException>(() => session.Query.All<TagType>()
90+
.Where(t => t.Id.In(IncludeAlgorithm.TemporaryTable, tagIds))
91+
.Set(t => t.ProjectedValueAdjustment, 2)
92+
.Update());
93+
}
94+
}
95+
96+
[Test]
97+
public void Test4()
98+
{
99+
using (var session = Domain.OpenSession())
100+
using (var tx = session.OpenTransaction()) {
101+
var updatedRows = session.Query.All<TagType>()
102+
.Where(t => tagIds.Contains(t.Id))
103+
.Set(t => t.ProjectedValueAdjustment, 2)
104+
.Update();
105+
Assert.That(updatedRows, Is.EqualTo(100));
106+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == 2 && t.Id <= 200), Is.EqualTo(100));
107+
Assert.That(session.Query.All<TagType>().Count(t => t.ProjectedValueAdjustment == -1 && t.Id > 700), Is.EqualTo(1));
108+
}
109+
}
110+
}
111+
}

Extensions/Xtensive.Orm.BulkOperations.Tests/Other.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Copyright (C) 2019-2020 Xtensive LLC.
1+
// Copyright (C) 2012-2020 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
4+
// Created by: Alexander Ovchinnikov
5+
// Created: 2012.02.29
46

57
using System;
68
using System.Collections.Generic;
@@ -348,5 +350,34 @@ public void In()
348350
trx.Complete();
349351
}
350352
}
353+
354+
[Test]
355+
public void InWithCombinationWithFieldUsageUpdate()
356+
{
357+
using (Session session = Domain.OpenSession())
358+
using (TransactionScope trx = session.OpenTransaction()) {
359+
var idsToUpdate = new[] { 99, 100, 102 };
360+
var prefix = "abc";
361+
362+
var bar1 = new Bar(session, 100) { Name = "test1", Count = 3 };
363+
var bar2 = new Bar(session, 101) { Name = "test2", Count = 4 };
364+
var bar3 = new Bar(session, 102) { Name = "test3", Count = 5 };
365+
session.SaveChanges();
366+
367+
var updatedCount = session.Query.All<Bar>()
368+
.Where(b => b.Id.In(IncludeAlgorithm.ComplexCondition, idsToUpdate))
369+
.Update(bar => new Bar(session) { Name = prefix + bar.Name });
370+
Assert.That(updatedCount, Is.EqualTo(2));
371+
372+
var all = session.Query.All<Bar>().Where(b=> b.Id == 100 || b.Id == 101 || b.Id == 102).ToList();
373+
var updatedEntities = all.Where(b => b.Id.In(idsToUpdate));
374+
Assert.That(updatedEntities.All(e => e.Name.StartsWith(prefix)), Is.True);
375+
376+
var leftEntities = all.Where(b => !b.Id.In(idsToUpdate));
377+
Assert.That(leftEntities.All(e => e.Name.StartsWith(prefix)), Is.False);
378+
379+
trx.Complete();
380+
}
381+
}
351382
}
352383
}

Extensions/Xtensive.Orm.BulkOperations.Tests/Xtensive.Orm.BulkOperations.Tests.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputPath>..\..\_Build\$(Configuration)\lib\</OutputPath>
3+
<OutputPath>$(SolutionDir)_Build\$(Configuration)\lib\</OutputPath>
44
<DocumentationFile />
55
</PropertyGroup>
6-
<PropertyGroup>
7-
<TargetFramework>netcoreapp3.1</TargetFramework>
8-
</PropertyGroup>
9-
<Import Project="..\..\MSBuild\DataObjects.Net.InternalBuild.targets" />
6+
<Import Project="$(SolutionDir)MSBuild\DataObjects.Net.InternalBuild.targets" />
107
<ItemGroup>
118
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.2" />
129
<PackageReference Include="NUnit" Version="3.12.0" />

Extensions/Xtensive.Orm.BulkOperations/Internals/QueryOperation.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,44 @@ protected QueryOperation(QueryProvider queryProvider)
2626
protected override int ExecuteInternal()
2727
{
2828
var e = query.Expression.Visit((MethodCallExpression ex) => {
29-
if (ex.Method.DeclaringType == WellKnownMembers.QueryableExtensionsType
30-
&& string.Equals(ex.Method.Name, WellKnownMembers.InMethodName, StringComparison.Ordinal)
31-
&& ex.Arguments.Count > 1) {
32-
if (ex.Arguments[1].Type == WellKnownMembers.IncludeAlgorithmType) {
33-
var v = (IncludeAlgorithm) ex.Arguments[1].Invoke();
34-
if (v == IncludeAlgorithm.TemporaryTable) {
35-
throw new NotSupportedException("IncludeAlgorithm.TemporaryTable is not supported");
36-
}
3729

38-
if (v == IncludeAlgorithm.Auto) {
30+
var methodInfo = ex.Method;
31+
//rewrite localCollection.Contains(entity.SomeField) -> entity.SomeField.In(localCollection)
32+
if (methodInfo.DeclaringType == WellKnownMembers.EnumerableType &&
33+
string.Equals(methodInfo.Name, "Contains", StringComparison.Ordinal) &&
34+
ex.Arguments.Count == 2) {
35+
var localCollection = ex.Arguments[0];//IEnumerable<T>
36+
var valueToCheck = ex.Arguments[1];
37+
var genericInMethod = WellKnownMembers.InMethod.MakeGenericMethod(new[] { valueToCheck.Type });
38+
ex = Expression.Call(genericInMethod, valueToCheck, Expression.Constant(IncludeAlgorithm.ComplexCondition), localCollection);
39+
methodInfo = ex.Method;
40+
}
41+
42+
if (methodInfo.DeclaringType == WellKnownMembers.QueryableExtensionsType &&
43+
string.Equals(methodInfo.Name, WellKnownMembers.InMethodName, StringComparison.Ordinal) &&
44+
ex.Arguments.Count > 1) {
45+
if (ex.Arguments[1].Type == WellKnownMembers.IncludeAlgorithmType) {
46+
var algorithm = (IncludeAlgorithm) ex.Arguments[1].Invoke();
47+
if (algorithm == IncludeAlgorithm.TemporaryTable) {
48+
throw new NotSupportedException("IncludeAlgorithm.TemporaryTable is not supported");
49+
}
50+
51+
if (algorithm == IncludeAlgorithm.Auto) {
52+
var arguments = ex.Arguments.ToList();
53+
arguments[1] = Expression.Constant(IncludeAlgorithm.ComplexCondition);
54+
ex = Expression.Call(methodInfo, arguments);
55+
}
56+
}
57+
else {
3958
var arguments = ex.Arguments.ToList();
40-
arguments[1] = Expression.Constant(IncludeAlgorithm.ComplexCondition);
41-
ex = Expression.Call(ex.Method, arguments);
59+
arguments.Insert(1, Expression.Constant(IncludeAlgorithm.ComplexCondition));
60+
ex = Expression.Call(WellKnownMembers.InMethod.MakeGenericMethod(methodInfo.GetGenericArguments()),
61+
arguments.ToArray());
4262
}
4363
}
44-
else {
45-
var arguments = ex.Arguments.ToList();
46-
arguments.Insert(1, Expression.Constant(IncludeAlgorithm.ComplexCondition));
47-
ex = Expression.Call(WellKnownMembers.InMethod.MakeGenericMethod(ex.Method.GetGenericArguments()),
48-
arguments.ToArray());
49-
}
50-
}
5164

52-
return ex;
53-
});
65+
return ex;
66+
});
5467
query = QueryProvider.CreateQuery<T>(e);
5568
return 0;
5669
}

Extensions/Xtensive.Orm.BulkOperations/Xtensive.Orm.BulkOperations.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<IsPackable>true</IsPackable>
4-
<OutputPath>..\..\_Build\$(Configuration)\lib\</OutputPath>
5-
<DocumentationFile>..\..\_Build\$(Configuration)\lib\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
4+
<OutputPath>$(SolutionDir)_Build\$(Configuration)\lib\</OutputPath>
5+
<DocumentationFile>$(SolutionDir)_Build\$(Configuration)\lib\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
66
</PropertyGroup>
77
<PropertyGroup>
8-
<TargetFramework>netstandard2.1</TargetFramework>
98
<PackageId>Xtensive.Orm.BulkOperations</PackageId>
109
<Title>Bulk operations extension for $(DoProductName)</Title>
1110
<AssemblyTitle>$(Title)</AssemblyTitle>
1211
<PackageDescription>Adds support for bulk insert, update and delete operations for $(DoProductName)-powered domain models</PackageDescription>
1312
<SignAssembly>true</SignAssembly>
14-
<AssemblyOriginatorKeyFile>..\Extensions.snk</AssemblyOriginatorKeyFile>
13+
<AssemblyOriginatorKeyFile>$(ExtensionsKeyFile)</AssemblyOriginatorKeyFile>
1514
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1615
</PropertyGroup>
1716
<ItemGroup>

Extensions/Xtensive.Orm.Localization.Tests/Xtensive.Orm.Localization.Tests.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<OutputPath>..\..\_Build\$(Configuration)\lib\</OutputPath>
3+
<OutputPath>$(SolutionDir)_Build\$(Configuration)\lib\</OutputPath>
44
<DocumentationFile />
55
</PropertyGroup>
6-
<PropertyGroup>
7-
<TargetFramework>netcoreapp3.1</TargetFramework>
8-
</PropertyGroup>
9-
<Import Project="..\..\MSBuild\DataObjects.Net.InternalBuild.targets" />
6+
<Import Project="$(SolutionDir)MSBuild\DataObjects.Net.InternalBuild.targets" />
107
<ItemGroup>
118
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.2" />
129
<PackageReference Include="NUnit" Version="3.12.0" />

0 commit comments

Comments
 (0)