Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
NPoco
提交
25eafd9a
N
NPoco
项目概览
jobily
/
NPoco
9 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NPoco
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
25eafd9a
编写于
10月 15, 2020
作者:
A
Adam Schroder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some nullable reference type annotations
上级
d79c076f
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
129 addition
and
131 deletion
+129
-131
src/NPoco.SqlServer/DatabaseTypes/SqlServer2012DatabaseType.cs
...Poco.SqlServer/DatabaseTypes/SqlServer2012DatabaseType.cs
+2
-2
src/NPoco.SqlServer/DatabaseTypes/SqlServerDatabaseType.cs
src/NPoco.SqlServer/DatabaseTypes/SqlServerDatabaseType.cs
+1
-1
src/NPoco.SqlServer/NPoco.SqlServer.csproj
src/NPoco.SqlServer/NPoco.SqlServer.csproj
+1
-0
src/NPoco.SqlServer/SqlBulkCopyHelper.cs
src/NPoco.SqlServer/SqlBulkCopyHelper.cs
+5
-4
src/NPoco.SqlServer/SqlServerDatabase.cs
src/NPoco.SqlServer/SqlServerDatabase.cs
+3
-3
src/NPoco/Database.cs
src/NPoco/Database.cs
+109
-114
src/NPoco/IDatabase.cs
src/NPoco/IDatabase.cs
+8
-7
未找到文件。
src/NPoco.SqlServer/DatabaseTypes/SqlServer2012DatabaseType.cs
浏览文件 @
25eafd9a
...
@@ -21,10 +21,10 @@ public override string BuildPageQuery(long skip, long take, PagingHelper.SQLPart
...
@@ -21,10 +21,10 @@ public override string BuildPageQuery(long skip, long take, PagingHelper.SQLPart
return
sqlPage
;
return
sqlPage
;
}
}
public
override
string
GetAutoIncrementExpression
(
TableInfo
ti
)
public
override
string
?
GetAutoIncrementExpression
(
TableInfo
ti
)
{
{
if
(!
string
.
IsNullOrEmpty
(
ti
.
SequenceName
))
if
(!
string
.
IsNullOrEmpty
(
ti
.
SequenceName
))
return
string
.
Format
(
"NEXT VALUE FOR {0}"
,
ti
.
SequenceName
)
;
return
$"NEXT VALUE FOR
{
ti
.
SequenceName
}
"
;
return
null
;
return
null
;
}
}
...
...
src/NPoco.SqlServer/DatabaseTypes/SqlServerDatabaseType.cs
浏览文件 @
25eafd9a
...
@@ -74,7 +74,7 @@ public override IsolationLevel GetDefaultTransactionIsolationLevel()
...
@@ -74,7 +74,7 @@ public override IsolationLevel GetDefaultTransactionIsolationLevel()
return
base
.
LookupDbType
(
type
,
name
);
return
base
.
LookupDbType
(
type
,
name
);
}
}
public
override
void
InsertBulk
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
pocos
,
InsertBulkOptions
options
)
public
override
void
InsertBulk
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
pocos
,
InsertBulkOptions
?
options
)
{
{
SqlBulkCopyHelper
.
BulkInsert
(
db
,
pocos
,
options
);
SqlBulkCopyHelper
.
BulkInsert
(
db
,
pocos
,
options
);
}
}
...
...
src/NPoco.SqlServer/NPoco.SqlServer.csproj
浏览文件 @
25eafd9a
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
<LangVersion>8.0</LangVersion>
<LangVersion>8.0</LangVersion>
<nullable>enable</nullable>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
...
...
src/NPoco.SqlServer/SqlBulkCopyHelper.cs
浏览文件 @
25eafd9a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data
;
using
System.Data.Common
;
using
System.Data.Common
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.Data.SqlClient
;
using
Microsoft.Data.SqlClient
;
...
@@ -13,12 +14,12 @@ public class SqlBulkCopyHelper
...
@@ -13,12 +14,12 @@ public class SqlBulkCopyHelper
public
static
Func
<
DbConnection
,
SqlConnection
>
SqlConnectionResolver
=
dbConn
=>
(
SqlConnection
)
dbConn
;
public
static
Func
<
DbConnection
,
SqlConnection
>
SqlConnectionResolver
=
dbConn
=>
(
SqlConnection
)
dbConn
;
public
static
Func
<
DbTransaction
,
SqlTransaction
>
SqlTransactionResolver
=
dbTran
=>
(
SqlTransaction
)
dbTran
;
public
static
Func
<
DbTransaction
,
SqlTransaction
>
SqlTransactionResolver
=
dbTran
=>
(
SqlTransaction
)
dbTran
;
public
static
void
BulkInsert
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
InsertBulkOptions
insertBulkOptions
)
public
static
void
BulkInsert
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
InsertBulkOptions
?
insertBulkOptions
)
{
{
BulkInsert
(
db
,
list
,
SqlBulkCopyOptions
.
Default
,
insertBulkOptions
);
BulkInsert
(
db
,
list
,
SqlBulkCopyOptions
.
Default
,
insertBulkOptions
);
}
}
public
static
void
BulkInsert
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
SqlBulkCopyOptions
sqlBulkCopyOptions
,
InsertBulkOptions
insertBulkOptions
)
public
static
void
BulkInsert
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
SqlBulkCopyOptions
sqlBulkCopyOptions
,
InsertBulkOptions
?
insertBulkOptions
)
{
{
using
(
var
bulkCopy
=
new
SqlBulkCopy
(
SqlConnectionResolver
(
db
.
Connection
),
sqlBulkCopyOptions
,
SqlTransactionResolver
(
db
.
Transaction
)))
using
(
var
bulkCopy
=
new
SqlBulkCopy
(
SqlConnectionResolver
(
db
.
Connection
),
sqlBulkCopyOptions
,
SqlTransactionResolver
(
db
.
Transaction
)))
{
{
...
@@ -42,7 +43,7 @@ public static async Task BulkInsertAsync<T>(IDatabase db, IEnumerable<T> list, S
...
@@ -42,7 +43,7 @@ public static async Task BulkInsertAsync<T>(IDatabase db, IEnumerable<T> list, S
}
}
private
static
DataTable
BuildBulkInsertDataTable
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
SqlBulkCopy
bulkCopy
,
SqlBulkCopyOptions
sqlBulkCopyOptions
,
InsertBulkOptions
insertBulkOptions
)
private
static
DataTable
BuildBulkInsertDataTable
<
T
>(
IDatabase
db
,
IEnumerable
<
T
>
list
,
SqlBulkCopy
bulkCopy
,
SqlBulkCopyOptions
sqlBulkCopyOptions
,
InsertBulkOptions
?
insertBulkOptions
)
{
{
var
pocoData
=
db
.
PocoDataFactory
.
ForType
(
typeof
(
T
));
var
pocoData
=
db
.
PocoDataFactory
.
ForType
(
typeof
(
T
));
...
@@ -78,7 +79,7 @@ private static DataTable BuildBulkInsertDataTable<T>(IDatabase db, IEnumerable<T
...
@@ -78,7 +79,7 @@ private static DataTable BuildBulkInsertDataTable<T>(IDatabase db, IEnumerable<T
var
values
=
new
object
[
cols
.
Count
];
var
values
=
new
object
[
cols
.
Count
];
for
(
var
i
=
0
;
i
<
values
.
Length
;
i
++)
for
(
var
i
=
0
;
i
<
values
.
Length
;
i
++)
{
{
var
value
=
cols
[
i
].
Value
.
GetValue
(
item
);
var
value
=
cols
[
i
].
Value
.
GetValue
(
item
!
);
if
(
db
.
Mappers
!=
null
)
if
(
db
.
Mappers
!=
null
)
{
{
value
=
db
.
Mappers
.
FindAndExecute
(
x
=>
x
.
GetToDbConverter
(
cols
[
i
].
Value
.
ColumnType
,
cols
[
i
].
Value
.
MemberInfoData
.
MemberInfo
),
value
);
value
=
db
.
Mappers
.
FindAndExecute
(
x
=>
x
.
GetToDbConverter
(
cols
[
i
].
Value
.
ColumnType
,
cols
[
i
].
Value
.
MemberInfoData
.
MemberInfo
),
value
);
...
...
src/NPoco.SqlServer/SqlServerDatabase.cs
浏览文件 @
25eafd9a
...
@@ -8,14 +8,14 @@ namespace NPoco.SqlServer
...
@@ -8,14 +8,14 @@ namespace NPoco.SqlServer
{
{
public
class
SqlServerDatabase
:
Database
public
class
SqlServerDatabase
:
Database
{
{
private
readonly
IPollyPolicy
_pollyPolicy
;
private
readonly
IPollyPolicy
?
_pollyPolicy
;
public
SqlServerDatabase
(
string
connectionString
,
IPollyPolicy
pollyPolicy
=
null
)
public
SqlServerDatabase
(
string
connectionString
,
IPollyPolicy
?
pollyPolicy
=
null
)
:
this
(
connectionString
,
Singleton
<
SqlServer2012DatabaseType
>.
Instance
,
pollyPolicy
)
:
this
(
connectionString
,
Singleton
<
SqlServer2012DatabaseType
>.
Instance
,
pollyPolicy
)
{
{
}
}
public
SqlServerDatabase
(
string
connectionString
,
SqlServerDatabaseType
databaseType
,
IPollyPolicy
pollyPolicy
)
public
SqlServerDatabase
(
string
connectionString
,
SqlServerDatabaseType
databaseType
,
IPollyPolicy
?
pollyPolicy
)
:
base
(
connectionString
,
databaseType
,
SqlClientFactory
.
Instance
)
:
base
(
connectionString
,
databaseType
,
SqlClientFactory
.
Instance
)
{
{
_pollyPolicy
=
pollyPolicy
;
_pollyPolicy
=
pollyPolicy
;
...
...
src/NPoco/Database.cs
浏览文件 @
25eafd9a
此差异已折叠。
点击以展开。
src/NPoco/IDatabase.cs
浏览文件 @
25eafd9a
#
nullable
enable
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq.Expressions
;
using
System.Linq.Expressions
;
...
@@ -26,12 +27,12 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
...
@@ -26,12 +27,12 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
/// <summary>
/// <summary>
/// Insert POCO's into database using SqlBulkCopy for SqlServer (other DB's currently fall back to looping each row)
/// Insert POCO's into database using SqlBulkCopy for SqlServer (other DB's currently fall back to looping each row)
/// </summary>
/// </summary>
void
InsertBulk
<
T
>(
IEnumerable
<
T
>
pocos
,
InsertBulkOptions
options
=
null
);
void
InsertBulk
<
T
>(
IEnumerable
<
T
>
pocos
,
InsertBulkOptions
?
options
=
null
);
/// <summary>
/// <summary>
/// Insert POCO's into database by concatenating sql using the provided batch options
/// Insert POCO's into database by concatenating sql using the provided batch options
/// </summary>
/// </summary>
int
InsertBatch
<
T
>(
IEnumerable
<
T
>
pocos
,
BatchOptions
options
=
null
);
int
InsertBatch
<
T
>(
IEnumerable
<
T
>
pocos
,
BatchOptions
?
options
=
null
);
/// <summary>
/// <summary>
/// Update POCO in the specified table, primary key and primarkey value
/// Update POCO in the specified table, primary key and primarkey value
...
@@ -46,12 +47,12 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
...
@@ -46,12 +47,12 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
/// <summary>
/// <summary>
/// Update POCO in the specified table, primary key, primarkey value for only the columns specified
/// Update POCO in the specified table, primary key, primarkey value for only the columns specified
/// </summary>
/// </summary>
int
Update
(
string
tableName
,
string
primaryKeyName
,
object
poco
,
object
primaryKeyValue
,
IEnumerable
<
string
>
columns
);
int
Update
(
string
tableName
,
string
primaryKeyName
,
object
poco
,
object
?
primaryKeyValue
,
IEnumerable
<
string
>?
columns
);
/// <summary>
/// <summary>
/// Update POCO in the specified table, primary key for only the columns specified
/// Update POCO in the specified table, primary key for only the columns specified
/// </summary>
/// </summary>
int
Update
(
string
tableName
,
string
primaryKeyName
,
object
poco
,
IEnumerable
<
string
>
columns
);
int
Update
(
string
tableName
,
string
primaryKeyName
,
object
poco
,
IEnumerable
<
string
>
?
columns
);
/// <summary>
/// <summary>
/// Update POCO by convention or configuration for only the columns specified
/// Update POCO by convention or configuration for only the columns specified
...
@@ -61,7 +62,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
...
@@ -61,7 +62,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
/// <summary>
/// <summary>
/// Update POCO by primary key for only the columns specified
/// Update POCO by primary key for only the columns specified
/// </summary>
/// </summary>
int
Update
(
object
poco
,
object
primaryKeyValue
,
IEnumerable
<
string
>
columns
);
int
Update
(
object
poco
,
object
primaryKeyValue
,
IEnumerable
<
string
>
?
columns
);
/// <summary>
/// <summary>
/// Update POCO by convention or configuration
/// Update POCO by convention or configuration
...
@@ -97,7 +98,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
...
@@ -97,7 +98,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
/// <summary>
/// <summary>
/// Update POCO's into database by concatenating sql using the provided batch options
/// Update POCO's into database by concatenating sql using the provided batch options
/// </summary>
/// </summary>
int
UpdateBatch
<
T
>(
IEnumerable
<
UpdateBatch
<
T
>>
pocos
,
BatchOptions
options
=
null
);
int
UpdateBatch
<
T
>(
IEnumerable
<
UpdateBatch
<
T
>>
pocos
,
BatchOptions
?
options
=
null
);
/// <summary>
/// <summary>
/// Generate an update statement using a Fluent syntax. Remember to call Execute.
/// Generate an update statement using a Fluent syntax. Remember to call Execute.
...
@@ -112,7 +113,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
...
@@ -112,7 +113,7 @@ public interface IDatabase : IAsyncDatabase, IDatabaseQuery, IDatabaseConfig
/// <summary>
/// <summary>
/// Delete POCO specifying the table name, primary key name and primary key value
/// Delete POCO specifying the table name, primary key name and primary key value
/// </summary>
/// </summary>
int
Delete
(
string
tableName
,
string
primaryKeyName
,
object
poco
,
object
primaryKeyValue
);
int
Delete
(
string
tableName
,
string
primaryKeyName
,
object
?
poco
,
object
?
primaryKeyValue
);
/// <summary>
/// <summary>
/// Delete POCO using convention or configuration
/// Delete POCO using convention or configuration
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录