Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
EFCore.BulkExtensions
提交
ff6488b8
E
EFCore.BulkExtensions
项目概览
jobily
/
EFCore.BulkExtensions
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
EFCore.BulkExtensions
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ff6488b8
编写于
7月 10, 2023
作者:
B
Boris Djurdjevic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added IDataReader in config for streaming
上级
348659a7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
56 addition
and
10 deletion
+56
-10
EFCore.BulkExtensions.Tests/EFCore.BulkExtensions.Tests.csproj
...e.BulkExtensions.Tests/EFCore.BulkExtensions.Tests.csproj
+1
-0
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
+21
-0
EFCore.BulkExtensions/BulkConfig.cs
EFCore.BulkExtensions/BulkConfig.cs
+11
-5
EFCore.BulkExtensions/DbContextBulkTransaction.cs
EFCore.BulkExtensions/DbContextBulkTransaction.cs
+2
-1
EFCore.BulkExtensions/SqlAdapters/MySql/MySqlAdapter.cs
EFCore.BulkExtensions/SqlAdapters/MySql/MySqlAdapter.cs
+10
-2
EFCore.BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
....BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
+11
-2
未找到文件。
EFCore.BulkExtensions.Tests/EFCore.BulkExtensions.Tests.csproj
浏览文件 @
ff6488b8
...
...
@@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="DelegateDecompiler.EntityFrameworkCore5" Version="0.32.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.HierarchyId" Version="4.0.0" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="7.0.8" />
...
...
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
浏览文件 @
ff6488b8
using
EFCore.BulkExtensions.SqlAdapters
;
using
FastMember
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Metadata.Internal
;
using
NetTopologySuite.Geometries
;
...
...
@@ -1435,4 +1436,24 @@ public class EFCoreBulkTestAtypical
};
//context.BulkRead(list2, bulkConfig); // Throws: 'The required column 'xmin' was not present in the results of a 'FromSql' operation.'
}
[
Theory
]
[
InlineData
(
SqlType
.
SqlServer
)]
private
void
DataReaderTest
(
SqlType
sqlType
)
{
ContextUtil
.
DatabaseType
=
sqlType
;
using
var
context
=
new
TestContext
(
ContextUtil
.
GetOptions
());
context
.
Truncate
<
Customer
>();
var
entities
=
new
List
<
Customer
>
{
new
Customer
{
Name
=
"Cust 1"
},
new
Customer
{
Name
=
"Cust 2"
},
};
using
(
var
reader
=
ObjectReader
.
Create
(
entities
))
context
.
BulkInsert
(
new
List
<
Customer
>(),
new
BulkConfig
{
DataReader
=
reader
});
// , EnableStreaming = true
}
}
EFCore.BulkExtensions/BulkConfig.cs
浏览文件 @
ff6488b8
using
Microsoft.Data.SqlClient
;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq.Expressions
;
...
...
@@ -54,11 +55,6 @@ public class BulkConfig
/// </summary>
public
int
?
BulkCopyTimeout
{
get
;
set
;
}
/// <summary>
/// Propagated to SqlBulkCopy util object.
/// </summary>
public
bool
EnableStreaming
{
get
;
set
;
}
/// <summary>
/// When set to <c>true</c> Temp tables are created as #Temporary. More info: <c>https://www.sqlservertutorial.net/sql-server-basics/sql-server-temporary-tables/</c>
/// </summary>
...
...
@@ -96,6 +92,16 @@ public class BulkConfig
/// </summary>
public
Dictionary
<
string
,
string
>?
CustomSourceDestinationMappingColumns
{
get
;
set
;
}
/// <summary>
/// When configured data is loaded from this object instead of entity list which should be empty
/// </summary>
public
IDataReader
?
DataReader
{
get
;
set
;
}
/// <summary>
/// Can be used when DataReader ia also configured and when set it is propagated to SqlBulkCopy util object.
/// </summary>
public
bool
EnableStreaming
{
get
;
set
;
}
/// <summary>
/// Can be set to True if want to have tracking of entities from BulkRead or when SetOutputIdentity is set.
/// </summary>
...
...
EFCore.BulkExtensions/DbContextBulkTransaction.cs
浏览文件 @
ff6488b8
...
...
@@ -22,7 +22,8 @@ internal static class DbContextBulkTransaction
operationType
!=
OperationType
.
InsertOrUpdateOrDelete
&&
operationType
!=
OperationType
.
Truncate
&&
operationType
!=
OperationType
.
SaveChanges
&&
(
bulkConfig
==
null
||
bulkConfig
.
CustomSourceTableName
==
null
))
(
bulkConfig
==
null
||
bulkConfig
.
CustomSourceTableName
==
null
)
&&
(
bulkConfig
==
null
||
bulkConfig
.
DataReader
==
null
))
{
return
;
}
...
...
EFCore.BulkExtensions/SqlAdapters/MySql/MySqlAdapter.cs
浏览文件 @
ff6488b8
...
...
@@ -56,13 +56,21 @@ public class MySqlAdapter : ISqlOperationsAdapter
SetMySqlBulkCopyConfig
(
mySqlBulkCopy
,
tableInfo
);
var
dataTable
=
GetDataTable
(
context
,
type
,
entities
,
mySqlBulkCopy
,
tableInfo
);
IDataReader
?
dataReader
=
tableInfo
.
BulkConfig
.
DataReader
;
if
(
isAsync
)
{
await
mySqlBulkCopy
.
WriteToServerAsync
(
dataTable
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
dataReader
==
null
)
await
mySqlBulkCopy
.
WriteToServerAsync
(
dataTable
,
cancellationToken
).
ConfigureAwait
(
false
);
else
await
mySqlBulkCopy
.
WriteToServerAsync
(
dataReader
,
cancellationToken
).
ConfigureAwait
(
false
);
}
else
{
mySqlBulkCopy
.
WriteToServer
(
dataTable
);
if
(
dataReader
==
null
)
mySqlBulkCopy
.
WriteToServer
(
dataTable
);
else
mySqlBulkCopy
.
WriteToServer
(
dataReader
);
}
}
finally
...
...
EFCore.BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
浏览文件 @
ff6488b8
...
...
@@ -6,6 +6,7 @@ using NetTopologySuite.IO;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.Common
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
...
...
@@ -60,13 +61,21 @@ public class SqlServerAdapter : ISqlOperationsAdapter
try
{
var
dataTable
=
GetDataTable
(
context
,
type
,
entities
,
sqlBulkCopy
,
tableInfo
);
IDataReader
?
dataReader
=
tableInfo
.
BulkConfig
.
DataReader
;
if
(
isAsync
)
{
await
sqlBulkCopy
.
WriteToServerAsync
(
dataTable
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
dataReader
==
null
)
await
sqlBulkCopy
.
WriteToServerAsync
(
dataTable
,
cancellationToken
).
ConfigureAwait
(
false
);
else
await
sqlBulkCopy
.
WriteToServerAsync
(
dataReader
,
cancellationToken
).
ConfigureAwait
(
false
);
}
else
{
sqlBulkCopy
.
WriteToServer
(
dataTable
);
if
(
dataReader
==
null
)
sqlBulkCopy
.
WriteToServer
(
dataTable
);
else
sqlBulkCopy
.
WriteToServer
(
dataReader
);
}
}
catch
(
InvalidOperationException
ex
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录