Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
EFCore.BulkExtensions
提交
8d6f2372
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 搜索 >>
提交
8d6f2372
编写于
6月 28, 2023
作者:
B
Boris Djurdjevic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changes
上级
9b28a873
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
11 deletion
+101
-11
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
+52
-5
EFCore.BulkExtensions.Tests/TestContext.cs
EFCore.BulkExtensions.Tests/TestContext.cs
+20
-0
EFCore.BulkExtensions/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs
...ulkExtensions/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs
+28
-5
EFCore.BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
....BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
+1
-1
未找到文件。
EFCore.BulkExtensions.Tests/EFCoreBulkTestAtypical.cs
浏览文件 @
8d6f2372
using
EFCore.BulkExtensions.SqlAdapters
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Metadata.Internal
;
using
NetTopologySuite.Geometries
;
using
System
;
using
System.Collections.Generic
;
...
...
@@ -640,6 +641,7 @@ public class EFCoreBulkTestAtypical
[
Theory
]
[
InlineData
(
SqlType
.
SqlServer
)]
[
InlineData
(
SqlType
.
PostgreSql
)]
[
InlineData
(
SqlType
.
Sqlite
)]
//Not supported
private
void
ShadowFKPropertiesTest
(
SqlType
sqlType
)
// with Foreign Key as Shadow Property
{
...
...
@@ -658,7 +660,6 @@ public class EFCoreBulkTestAtypical
}
//context.BulkDelete(context.Items.ToList()); // On table with FK Truncate does not work
if
(!
context
.
Items
.
Any
())
{
for
(
int
i
=
1
;
i
<=
10
;
++
i
)
...
...
@@ -670,7 +671,7 @@ public class EFCoreBulkTestAtypical
Description
=
string
.
Concat
(
"info "
,
Guid
.
NewGuid
().
ToString
().
AsSpan
(
0
,
3
)),
Quantity
=
i
%
10
,
Price
=
i
/
(
i
%
5
+
1
),
TimeUpdated
=
DateTime
.
Now
,
TimeUpdated
=
sqlType
==
SqlType
.
PostgreSql
?
DateTime
.
UtcNow
:
DateTime
.
Now
,
ItemHistories
=
new
List
<
ItemHistory
>()
};
...
...
@@ -683,13 +684,22 @@ public class EFCoreBulkTestAtypical
var
entities
=
new
List
<
ItemLink
>();
for
(
int
i
=
0
;
i
<
EntitiesNumber
;
i
++)
{
entities
.
Add
(
new
ItemLink
var
itemLink
=
new
ItemLink
{
ItemLinkId
=
0
,
Item
=
items
[
i
%
items
.
Count
]
});
};
context
.
Entry
(
itemLink
).
Property
(
"Data"
).
CurrentValue
=
"aaa"
;
context
.
Entry
(
itemLink
).
Property
(
"ItemId"
).
CurrentValue
=
itemLink
.
Item
.
ItemId
;
entities
.
Add
(
itemLink
);
}
context
.
BulkInsert
(
entities
);
context
.
ItemLinks
.
AddRange
(
entities
);
context
.
SaveChanges
();
//context.BulkInsert(entities);
List
<
ItemLink
>
links
=
context
.
ItemLinks
.
ToList
();
Assert
.
True
(
links
.
Count
>
0
,
"ItemLink row count"
);
...
...
@@ -1388,4 +1398,41 @@ public class EFCoreBulkTestAtypical
context
.
BulkRead
(
list2
);
Assert
.
Equal
(
"At2"
,
list2
.
FirstOrDefault
()?.
Name
);
}
[
Theory
]
[
InlineData
(
SqlType
.
PostgreSql
)]
private
void
XminTest
(
SqlType
sqlType
)
{
ContextUtil
.
DatabaseType
=
sqlType
;
using
var
context
=
new
TestContext
(
ContextUtil
.
GetOptions
());
context
.
Truncate
<
Partner
>();
var
list
=
new
List
<
Partner
>
{
new
Partner
{
Name
=
"Aa1"
,
FirstName
=
"Ab2"
},
new
Partner
{
Name
=
"Ba1"
,
FirstName
=
"Bb2"
}
};
//context.BulkInsert(list);
context
.
Partners
.
AddRange
(
list
);
context
.
SaveChanges
();
var
first
=
context
.
Partners
.
FirstOrDefault
();
var
list2
=
new
List
<
Partner
>
{
new
Partner
{
Id
=
first
?.
Id
??
Guid
.
Empty
}
};
var
bulkConfig
=
new
BulkConfig
{
UpdateByProperties
=
new
List
<
string
>
{
nameof
(
Partner
.
Id
)
},
PropertiesToInclude
=
new
List
<
string
>
{
nameof
(
Partner
.
Id
),
nameof
(
Partner
.
Name
)
}
};
context
.
BulkRead
(
list2
,
bulkConfig
);
}
}
EFCore.BulkExtensions.Tests/TestContext.cs
浏览文件 @
8d6f2372
...
...
@@ -81,6 +81,8 @@ public class TestContext : DbContext
public
DbSet
<
Author
>
Authors
{
get
;
set
;
}
=
null
!;
public
DbSet
<
Partner
>
Partners
{
get
;
set
;
}
=
null
!;
public
static
bool
UseTopologyPostgres
{
get
;
set
;
}
=
false
;
public
TestContext
(
DbContextOptions
options
)
:
base
(
options
)
...
...
@@ -140,6 +142,8 @@ public class TestContext : DbContext
modelBuilder
.
Entity
<
FilePG
>().
Ignore
(
p
=>
p
.
Formats
);
modelBuilder
.
Entity
<
ItemLink
>().
Property
<
string
>(
"Data"
);
if
(
Database
.
IsSqlServer
())
{
modelBuilder
.
Entity
<
Document
>().
Property
(
p
=>
p
.
DocumentId
).
HasDefaultValueSql
(
"NEWID()"
);
...
...
@@ -213,6 +217,10 @@ public class TestContext : DbContext
modelBuilder
.
Entity
<
Box
>().
Property
(
p
=>
p
.
ElementContent
).
HasColumnType
(
"jsonb"
);
// with annotation not mapped since not used for others DBs
modelBuilder
.
Entity
<
Box
>().
Property
(
p
=>
p
.
DocumentContent
).
HasColumnType
(
"jsonb"
);
// with annotation not mapped since not used for others DBs
}
else
{
modelBuilder
.
Entity
<
Partner
>().
Ignore
(
p
=>
p
.
RowVersion
);
}
//modelBuilder.Entity<Modul>(buildAction => { buildAction.HasNoKey(); });
modelBuilder
.
Entity
<
Modul
>().
Property
(
et
=>
et
.
Code
).
ValueGeneratedNever
();
...
...
@@ -976,3 +984,15 @@ public class AddressCD
public
string
Postcode
{
get
;
set
;
}
public
string
Country
{
get
;
set
;
}
}
public
class
Partner
{
public
Guid
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
?
FirstName
{
get
;
set
;
}
[
Timestamp
]
[
DatabaseGenerated
(
DatabaseGeneratedOption
.
Computed
)]
[
Column
(
"xmin"
,
TypeName
=
"xid"
)]
public
uint
RowVersion
{
get
;
set
;
}
}
EFCore.BulkExtensions/SqlAdapters/PostgreSql/PostgreSqlAdapter.cs
浏览文件 @
8d6f2372
...
...
@@ -81,7 +81,7 @@ public class PostgreSqlAdapter : ISqlOperationsAdapter
continue
;
}
var
propertyValue
=
GetPropertyValue
(
tableInfo
,
propertyName
,
entity
);
var
propertyValue
=
GetPropertyValue
(
context
,
tableInfo
,
propertyName
,
entity
);
var
propertyColumnName
=
tableInfo
.
PropertyColumnNamesDict
.
GetValueOrDefault
(
propertyName
,
""
);
var
columnType
=
tableInfo
.
ColumnNamesTypesDict
[
propertyColumnName
];
...
...
@@ -167,18 +167,41 @@ public class PostgreSqlAdapter : ISqlOperationsAdapter
}
}
static
object
?
GetPropertyValue
<
T
>(
TableInfo
tableInfo
,
string
propertyName
,
T
entity
)
static
object
?
GetPropertyValue
<
T
>(
DbContext
context
,
TableInfo
tableInfo
,
string
propertyName
,
T
entity
)
{
var
propertyValue
=
default
(
object
);
if
(!
tableInfo
.
FastPropertyDict
.
ContainsKey
(
propertyName
.
Replace
(
'.'
,
'_'
))
||
entity
is
null
)
{
var
objectIdentifier
=
tableInfo
.
ObjectIdentifier
;
var
shadowPropertyColumnNamesDict
=
tableInfo
.
ColumnToPropertyDictionary
.
Where
(
a
=>
a
.
Value
.
IsShadowProperty
()).
ToDictionary
(
a
=>
a
.
Key
,
a
=>
a
.
Value
.
GetColumnName
(
objectIdentifier
));
if
(
shadowPropertyColumnNamesDict
.
ContainsKey
(
propertyName
))
{
if
(
tableInfo
.
BulkConfig
.
ShadowPropertyValue
==
null
)
{
propertyValue
=
context
.
Entry
(
entity
!).
Property
(
propertyName
).
CurrentValue
;
}
else
{
propertyValue
=
tableInfo
.
BulkConfig
.
ShadowPropertyValue
(
entity
!,
propertyName
);
}
if
(
tableInfo
.
ConvertibleColumnConverterDict
.
ContainsKey
(
propertyName
))
{
propertyValue
=
tableInfo
.
ConvertibleColumnConverterDict
[
propertyName
].
ConvertToProvider
.
Invoke
(
propertyValue
);
}
return
propertyValue
;
}
return
null
;
}
object
?
propertyValue
=
entity
;
//
object? propertyValue = entity;
string
fullPropertyName
=
string
.
Empty
;
foreach
(
var
entry
in
propertyName
.
AsSpan
().
Split
(
"."
))
{
if
(
propertyValue
==
null
)
if
(
entity
==
null
)
{
return
null
;
}
...
...
@@ -192,7 +215,7 @@ public class PostgreSqlAdapter : ISqlOperationsAdapter
fullPropertyName
=
new
string
(
entry
.
Token
);
}
propertyValue
=
tableInfo
.
FastPropertyDict
[
fullPropertyName
].
Get
(
propertyValue
);
propertyValue
=
tableInfo
.
FastPropertyDict
[
fullPropertyName
].
Get
(
entity
);
}
return
propertyValue
;
...
...
EFCore.BulkExtensions/SqlAdapters/SqlServer/SqlServerAdapter.cs
浏览文件 @
8d6f2372
...
...
@@ -805,7 +805,7 @@ public class SqlServerAdapter : ISqlOperationsAdapter
}
}
if
(
tableInfo
.
BulkConfig
.
EnableShadowProperties
)
if
(
tableInfo
.
BulkConfig
.
EnableShadowProperties
)
// TODO change for regular Shadow props to work even without this config
{
foreach
(
var
shadowPropertyName
in
shadowPropertyColumnNamesDict
.
Keys
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录