Skip to content

Commit ce374c8

Browse files
committed
Merge branch 'v5'
2 parents 4b17292 + 01b9f8a commit ce374c8

File tree

99 files changed

+2730
-1492
lines changed

Some content is hidden

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

99 files changed

+2730
-1492
lines changed

NPoco.sln

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30509.190
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C7A94BA4-5689-4651-872D-7D7711D2DEDF}"
77
EndProject
@@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.Tests", "test\NPoco.T
1818
EndProject
1919
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.JsonNet", "src\NPoco.JsonNet\NPoco.JsonNet.csproj", "{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}"
2020
EndProject
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.SqlServer", "src\NPoco.SqlServer\NPoco.SqlServer.csproj", "{15554441-8CF4-4B7B-A6D3-914463BFFF42}"
22+
EndProject
2123
Global
2224
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2325
Debug|Any CPU = Debug|Any CPU
@@ -36,6 +38,10 @@ Global
3638
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Debug|Any CPU.Build.0 = Debug|Any CPU
3739
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Release|Any CPU.ActiveCfg = Release|Any CPU
3840
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Release|Any CPU.Build.0 = Release|Any CPU
3945
EndGlobalSection
4046
GlobalSection(SolutionProperties) = preSolution
4147
HideSolutionNode = FALSE
@@ -44,5 +50,9 @@ Global
4450
{56481BBA-35A1-4061-9FE8-0ED9E1B6A0A3} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
4551
{B39C2641-0655-47CC-A1A3-5E1F84714FB5} = {8EDBB46A-95F8-442E-A432-19A50ED0683B}
4652
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
53+
{15554441-8CF4-4B7B-A6D3-914463BFFF42} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
54+
EndGlobalSection
55+
GlobalSection(ExtensibilityGlobals) = postSolution
56+
SolutionGuid = {75EBE34D-2D61-4748-A383-DB920088B393}
4757
EndGlobalSection
4858
EndGlobal

build.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Properties {
99
$build_artifacts_dir = "$build_dir\build"
1010
$solution_dir = "$build_dir\src\NPoco"
1111
$jsonnet = "$build_dir\src\NPoco.JsonNet"
12+
$sqlserver = "$build_dir\src\NPoco.SqlServer"
1213
}
1314

1415
FormatTaskName (("-"*25) + "[{0}]" + ("-"*25))
@@ -19,10 +20,14 @@ Task Build -depends Clean {
1920
Write-Host "Creating BuildArtifacts" -ForegroundColor Green
2021
Exec { dotnet restore }
2122
Set-Location "$solution_dir"
22-
#$env:DNX_BUILD_VERSION="alpha02"
23-
Exec { dotnet pack --configuration release --output $build_artifacts_dir }
23+
if ($env:BUILD_SUFFIX -ne "") {
24+
$suffix = "/p:VersionSuffix=""$env:BUILD_SUFFIX"""
25+
}
26+
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
2427
Set-Location "$jsonnet"
25-
Exec { dotnet pack --configuration release --output $build_artifacts_dir }
28+
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
29+
Set-Location "$sqlserver"
30+
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
2631
}
2732

2833
Task Clean {

src/NPoco.JsonNet/NPoco.JsonNet.csproj

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,27 @@
22

33
<PropertyGroup>
44
<Description>Provides an implementation to use Json.NET as the serializer for serialized columns</Description>
5-
<VersionPrefix>4.0.0</VersionPrefix>
6-
<TargetFrameworks>net35;net45;net40;netstandard1.3;netstandard2.0</TargetFrameworks>
5+
<VersionPrefix>5.0.0</VersionPrefix>
6+
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
77
<AssemblyName>NPoco.JsonNet</AssemblyName>
88
<PackageId>NPoco.JsonNet</PackageId>
99
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
1010
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
11-
<PackageLicense>http://www.apache.org/licenses/LICENSE-2.0</PackageLicense>
12-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
1311
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
1412
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
1513
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1614
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1715
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1816
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
17+
<LangVersion>8.0</LangVersion>
1918
</PropertyGroup>
2019

2120
<ItemGroup>
2221
<ProjectReference Include="..\NPoco\NPoco.csproj" />
2322
</ItemGroup>
2423

2524
<ItemGroup>
26-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
25+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2726
</ItemGroup>
2827

29-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
30-
<Reference Include="System" />
31-
<Reference Include="Microsoft.CSharp" />
32-
</ItemGroup>
33-
34-
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
35-
<Reference Include="System" />
36-
<Reference Include="Microsoft.CSharp" />
37-
</ItemGroup>
38-
39-
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
40-
<Reference Include="System" />
41-
</ItemGroup>
42-
43-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
44-
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
45-
<PackageReference Include="System.Collections" Version="4.3.0" />
46-
<PackageReference Include="System.Linq" Version="4.3.0" />
47-
<PackageReference Include="System.Runtime" Version="4.3.0" />
48-
<PackageReference Include="System.Threading" Version="4.3.0" />
49-
</ItemGroup>
50-
51-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
52-
</ItemGroup>
53-
54-
<PropertyGroup>
55-
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
56-
</PropertyGroup>
57-
5828
</Project>

src/NPoco/DatabaseTypes/SqlServer2012DatabaseType.cs renamed to src/NPoco.SqlServer/DatabaseTypes/SqlServer2012DatabaseType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Data.SqlClient;
2+
using Microsoft.Data.SqlClient;
33
using System.Linq;
44

55
namespace NPoco.DatabaseTypes
@@ -21,10 +21,10 @@ public override string BuildPageQuery(long skip, long take, PagingHelper.SQLPart
2121
return sqlPage;
2222
}
2323

24-
public override string GetAutoIncrementExpression(TableInfo ti)
24+
public override string? GetAutoIncrementExpression(TableInfo ti)
2525
{
2626
if (!string.IsNullOrEmpty(ti.SequenceName))
27-
return string.Format("NEXT VALUE FOR {0}", ti.SequenceName);
27+
return $"NEXT VALUE FOR {ti.SequenceName}";
2828

2929
return null;
3030
}

src/NPoco/DatabaseTypes/SqlServerCEDatabaseType.cs renamed to src/NPoco.SqlServer/DatabaseTypes/SqlServerCEDatabaseType.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Data;
22
using System.Data.Common;
33
using System.Linq;
4+
using System.Threading.Tasks;
45

56
namespace NPoco.DatabaseTypes
67
{
@@ -19,14 +20,11 @@ public override object ExecuteInsert<T>(Database db, DbCommand cmd, string prima
1920
return db.ExecuteScalar<object>("SELECT @@@IDENTITY AS NewID;");
2021
}
2122

22-
23-
#if !NET35 && !NET40
24-
public override async System.Threading.Tasks.Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
23+
public override async Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
2524
{
26-
await db.ExecuteNonQueryHelperAsync(cmd);
27-
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;");
25+
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
26+
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;").ConfigureAwait(false);
2827
}
29-
#endif
3028

3129
public override IsolationLevel GetDefaultTransactionIsolationLevel()
3230
{

src/NPoco/DatabaseTypes/SqlServerDatabaseType.cs renamed to src/NPoco.SqlServer/DatabaseTypes/SqlServerDatabaseType.cs

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1+
using Microsoft.Data.SqlClient;
12
using System;
23
using System.Collections.Generic;
34
using System.Data;
45
using System.Data.Common;
5-
using System.Data.SqlClient;
66
using System.Linq;
7-
using System.Text.RegularExpressions;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using NPoco.SqlServer;
810

911
namespace NPoco.DatabaseTypes
1012
{
1113
public class SqlServerDatabaseType : DatabaseType
1214
{
1315
public bool UseOutputClause { get; set; }
1416

15-
private static readonly Regex OrderByAlias = new Regex(@"[\""\[\]\w]+\.([\[\]\""\w]+)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
16-
1717
public override bool UseColumnAliases()
1818
{
1919
return true;
2020
}
2121

2222
public override string BuildPageQuery(long skip, long take, PagingHelper.SQLParts parts, ref object[] args)
2323
{
24-
parts.sqlOrderBy = string.IsNullOrEmpty(parts.sqlOrderBy) ? null : OrderByAlias.Replace(parts.sqlOrderBy, "$1");
25-
var sqlPage = string.Format("SELECT {4} FROM (SELECT poco_base.*, ROW_NUMBER() OVER ({0}) poco_rn \nFROM ( \n{1}) poco_base ) poco_paged \nWHERE poco_rn > @{2} AND poco_rn <= @{3} \nORDER BY poco_rn",
26-
parts.sqlOrderBy ?? "ORDER BY (SELECT NULL /*poco_dual*/)", parts.sqlUnordered, args.Length, args.Length + 1, parts.sqlColumns);
27-
args = args.Concat(new object[] { skip, skip + take }).ToArray();
28-
29-
return sqlPage;
24+
return PagingHelper.BuildPaging(skip, take, parts, ref args);
3025
}
31-
26+
3227
private void AdjustSqlInsertCommandText(DbCommand cmd, bool useOutputClause)
3328
{
3429
if (!UseOutputClause && !useOutputClause)
@@ -57,26 +52,17 @@ public override object ExecuteInsert<T>(Database db, DbCommand cmd, string prima
5752
return db.ExecuteScalarHelper(cmd);
5853
}
5954

60-
#if !NET35 && !NET40
61-
public override System.Threading.Tasks.Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
55+
public override Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
6256
{
6357
AdjustSqlInsertCommandText(cmd, useOutputClause);
6458
return db.ExecuteScalarHelperAsync(cmd);
6559
}
66-
#endif
6760

6861
public override string GetExistsSql()
6962
{
7063
return "IF EXISTS (SELECT 1 FROM {0} WHERE {1}) SELECT 1 ELSE SELECT 0";
7164
}
7265

73-
#if !DNXCORE50
74-
public override void InsertBulk<T>(IDatabase db, IEnumerable<T> pocos)
75-
{
76-
SqlBulkCopyHelper.BulkInsert(db, pocos);
77-
}
78-
#endif
79-
8066
public override IsolationLevel GetDefaultTransactionIsolationLevel()
8167
{
8268
return IsolationLevel.ReadCommitted;
@@ -90,9 +76,19 @@ public override IsolationLevel GetDefaultTransactionIsolationLevel()
9076
return base.LookupDbType(type, name);
9177
}
9278

79+
public override void InsertBulk<T>(IDatabase db, IEnumerable<T> pocos, InsertBulkOptions? options)
80+
{
81+
SqlBulkCopyHelper.BulkInsert(db, pocos, options);
82+
}
83+
84+
public override Task InsertBulkAsync<T>(IDatabase db, IEnumerable<T> pocos, InsertBulkOptions options)
85+
{
86+
return SqlBulkCopyHelper.BulkInsertAsync(db, pocos, options);
87+
}
88+
9389
public override string GetProviderName()
9490
{
95-
return "System.Data.SqlClient";
91+
return "Microsoft.Data.SqlClient";
9692
}
9793

9894
public override object ProcessDefaultMappings(PocoColumn pocoColumn, object value)
@@ -103,5 +99,49 @@ public override object ProcessDefaultMappings(PocoColumn pocoColumn, object valu
10399
}
104100
return base.ProcessDefaultMappings(pocoColumn, value);
105101
}
102+
103+
104+
public override string FormatCommand(string sql, object[] args)
105+
{
106+
if (sql == null)
107+
return "";
108+
109+
var sb = new StringBuilder();
110+
if (args != null && args.Length > 0)
111+
{
112+
for (int i = 0; i < args.Length; i++)
113+
{
114+
var value = args[i];
115+
var formatted = args[i] as FormattedParameter;
116+
if (formatted != null)
117+
{
118+
value = formatted.Value;
119+
}
120+
121+
var p = new SqlParameter();
122+
ParameterHelper.SetParameterValue(this, p, args[i]);
123+
if (p.Size == 0 || p.SqlDbType == SqlDbType.UniqueIdentifier)
124+
{
125+
if (value == null && (p.SqlDbType == SqlDbType.NVarChar || p.SqlDbType == SqlDbType.VarChar))
126+
{
127+
sb.AppendFormat("DECLARE {0}{1} {2} = null\n", GetParameterPrefix(string.Empty), i, p.SqlDbType);
128+
}
129+
else
130+
{
131+
sb.AppendFormat("DECLARE {0}{1} {2} = '{3}'\n", GetParameterPrefix(string.Empty), i, p.SqlDbType, value);
132+
}
133+
}
134+
else
135+
{
136+
sb.AppendFormat("DECLARE {0}{1} {2}[{3}] = '{4}'\n", GetParameterPrefix(string.Empty), i, p.SqlDbType, p.Size, value);
137+
}
138+
}
139+
}
140+
141+
sb.AppendFormat("\n{0}", sql);
142+
143+
return sb.ToString();
144+
}
145+
106146
}
107147
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.Data.SqlClient;
4+
using Polly;
5+
using Polly.Retry;
6+
7+
namespace NPoco.SqlServer
8+
{
9+
public class DefaultPollyPolicy : IPollyPolicy
10+
{
11+
public virtual RetryPolicy RetryPolicy { get; set; } = RetryPolicyImp;
12+
13+
public virtual AsyncRetryPolicy AsyncRetryPolicy { get; set; } = RetryPolicyAsyncImp;
14+
15+
public static IEnumerable<TimeSpan> RetryTimes { get; set; } = new[]
16+
{
17+
TimeSpan.FromSeconds(1),
18+
TimeSpan.FromSeconds(3),
19+
TimeSpan.FromSeconds(5)
20+
};
21+
22+
private static readonly AsyncRetryPolicy RetryPolicyAsyncImp = Policy
23+
.Handle<SqlException>(SqlServerTransientExceptionDetector.ShouldRetryOn)
24+
.Or<TimeoutException>()
25+
.WaitAndRetryAsync(RetryTimes);
26+
27+
private static readonly RetryPolicy RetryPolicyImp = Policy
28+
.Handle<SqlException>(SqlServerTransientExceptionDetector.ShouldRetryOn)
29+
.Or<TimeoutException>()
30+
.WaitAndRetry(RetryTimes);
31+
}
32+
}

src/NPoco.SqlServer/IPollyPolicy.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Polly.Retry;
2+
3+
namespace NPoco.SqlServer
4+
{
5+
public interface IPollyPolicy
6+
{
7+
RetryPolicy RetryPolicy { get; set; }
8+
AsyncRetryPolicy AsyncRetryPolicy { get; set; }
9+
}
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>An extremely easy to use Micro-ORM supporting Sql Server.</Description>
5+
<VersionPrefix>5.0.0</VersionPrefix>
6+
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
7+
<AssemblyName>NPoco.SqlServer</AssemblyName>
8+
<PackageId>NPoco.SqlServer</PackageId>
9+
<Authors>Adam Schröder</Authors>
10+
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
11+
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
12+
<LangVersion>8.0</LangVersion>
13+
<nullable>enable</nullable>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.1" />
18+
<PackageReference Include="Polly" Version="7.2.1" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\src\NPoco\NPoco.csproj" />
23+
</ItemGroup>
24+
25+
</Project>

0 commit comments

Comments
 (0)