Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Efcore.Pg
提交
7886196b
E
Efcore.Pg
项目概览
jobily
/
Efcore.Pg
10 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Efcore.Pg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
7886196b
编写于
10月 20, 2022
作者:
S
Shay Rojansky
提交者:
GitHub
10月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Map uint rowversion properties to xmin (#2544)
Closes #2543
上级
3a26ceb3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
116 addition
and
3 deletion
+116
-3
EFCore.PG.sln.DotSettings
EFCore.PG.sln.DotSettings
+1
-0
src/EFCore.PG/Metadata/Conventions/NpgsqlConventionSetBuilder.cs
...ore.PG/Metadata/Conventions/NpgsqlConventionSetBuilder.cs
+1
-1
src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs
...ta/Conventions/NpgsqlPostgresModelFinalizingConvention.cs
+81
-0
test/EFCore.PG.Tests/Metadata/Conventions/NpgsqlPostgresModelFinalizingConventionTest.cs
...onventions/NpgsqlPostgresModelFinalizingConventionTest.cs
+32
-0
test/EFCore.PG.Tests/Metadata/Conventions/NpgsqlValueGenerationStrategyConventionTest.cs
...onventions/NpgsqlValueGenerationStrategyConventionTest.cs
+1
-2
未找到文件。
EFCore.PG.sln.DotSettings
浏览文件 @
7886196b
...
...
@@ -340,6 +340,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<s:Boolean x:Key="/Default/UserDictionary/Words/=Uniquifier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Uniquify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=varbit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xmin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=annotatable/@EntryIndexedValue">True</s:Boolean>
...
...
src/EFCore.PG/Metadata/Conventions/NpgsqlConventionSetBuilder.cs
浏览文件 @
7886196b
...
...
@@ -67,7 +67,7 @@ public override ConventionSet CreateConventionSet()
conventionSet
.
PropertyAnnotationChangedConventions
,
(
RelationalValueGenerationConvention
)
valueGenerationConvention
);
conventionSet
.
ModelFinalizingConventions
.
Add
(
valueGenerationStrategyConvention
);
conventionSet
.
ModelFinalizingConventions
.
Add
(
new
NpgsqlPostgres
ExtensionDiscovery
Convention
(
_typeMappingSource
));
conventionSet
.
ModelFinalizingConventions
.
Add
(
new
NpgsqlPostgres
ModelFinalizing
Convention
(
_typeMappingSource
));
ReplaceConvention
(
conventionSet
.
ModelFinalizingConventions
,
storeGenerationConvention
);
ReplaceConvention
(
conventionSet
.
ModelFinalizingConventions
,
...
...
src/EFCore.PG/Metadata/Conventions/NpgsqlPostgres
ExtensionDiscovery
Convention.cs
→
src/EFCore.PG/Metadata/Conventions/NpgsqlPostgres
ModelFinalizing
Convention.cs
浏览文件 @
7886196b
...
...
@@ -9,15 +9,15 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Conventions;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-conventions">Model building conventions</see>.
/// </remarks>
public
class
NpgsqlPostgres
ExtensionDiscovery
Convention
:
IModelFinalizingConvention
public
class
NpgsqlPostgres
ModelFinalizing
Convention
:
IModelFinalizingConvention
{
private
readonly
IRelationalTypeMappingSource
_typeMappingSource
;
/// <summary>
/// Creates a new instance of <see cref="NpgsqlPostgres
ExtensionDiscovery
Convention" />.
/// Creates a new instance of <see cref="NpgsqlPostgres
ModelFinalizing
Convention" />.
/// </summary>
/// <param name="typeMappingSource">The type mapping source to use.</param>
public
NpgsqlPostgres
ExtensionDiscovery
Convention
(
IRelationalTypeMappingSource
typeMappingSource
)
public
NpgsqlPostgres
ModelFinalizing
Convention
(
IRelationalTypeMappingSource
typeMappingSource
)
{
_typeMappingSource
=
typeMappingSource
;
}
...
...
@@ -29,29 +29,53 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder,
{
foreach
(
var
property
in
entityType
.
GetDeclaredProperties
())
{
var
typeMapping
=
(
RelationalTypeMapping
?)
property
.
FindTypeMapping
()
??
_typeMappingSource
.
FindMapping
((
IProperty
)
property
);
DiscoverPostgresExtensions
(
property
,
modelBuilder
);
ProcessRowVersionProperty
(
property
);
}
}
}
if
(
typeMapping
is
null
)
{
continue
;
}
/// <summary>
/// Discovers certain common PostgreSQL extensions based on property store types (e.g. hstore).
/// </summary>
/// <param name="property"></param>
/// <param name="modelBuilder"></param>
protected
virtual
void
DiscoverPostgresExtensions
(
IConventionProperty
property
,
IConventionModelBuilder
modelBuilder
)
{
var
typeMapping
=
(
RelationalTypeMapping
?)
property
.
FindTypeMapping
()
??
_typeMappingSource
.
FindMapping
((
IProperty
)
property
);
switch
(
typeMapping
.
StoreType
)
{
case
"hstore"
:
modelBuilder
.
HasPostgresExtension
(
"hstore"
);
continue
;
case
"citext"
:
modelBuilder
.
HasPostgresExtension
(
"citext"
);
continue
;
case
"ltree"
:
case
"lquery"
:
case
"ltxtquery"
:
modelBuilder
.
HasPostgresExtension
(
"ltree"
);
continue
;
}
if
(
typeMapping
is
not
null
)
{
switch
(
typeMapping
.
StoreType
)
{
case
"hstore"
:
modelBuilder
.
HasPostgresExtension
(
"hstore"
);
break
;
case
"citext"
:
modelBuilder
.
HasPostgresExtension
(
"citext"
);
break
;
case
"ltree"
:
case
"lquery"
:
case
"ltxtquery"
:
modelBuilder
.
HasPostgresExtension
(
"ltree"
);
break
;
}
}
}
/// <summary>
/// Detects properties which are uint, OnAddOrUpdate and configured as concurrency tokens, and maps these to the PostgreSQL
/// internal "xmin" column, which changes every time the row is modified.
/// </summary>
protected
virtual
void
ProcessRowVersionProperty
(
IConventionProperty
property
)
{
if
(
property
.
ValueGenerated
==
ValueGenerated
.
OnAddOrUpdate
&&
property
.
IsConcurrencyToken
&&
property
.
ClrType
==
typeof
(
uint
)
&&
property
.
GetValueConverter
()
is
null
)
{
property
.
Builder
.
HasColumnName
(
"xmin"
)?.
HasColumnType
(
"xid"
);
}
}
}
test/EFCore.PG.Tests/Metadata/Conventions/NpgsqlPostgresModelFinalizingConventionTest.cs
0 → 100644
浏览文件 @
7886196b
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using
System.ComponentModel.DataAnnotations
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities
;
namespace
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Conventions
;
public
class
NpgsqlPostgresModelFinalizingConventionTest
{
[
Fact
]
public
void
RowVersion_properties_get_mapped_to_xmin
()
{
var
modelBuilder
=
NpgsqlTestHelpers
.
Instance
.
CreateConventionBuilder
();
modelBuilder
.
Entity
<
Blog
>().
Property
(
b
=>
b
.
RowVersion
).
IsRowVersion
();
var
model
=
modelBuilder
.
FinalizeModel
();
var
entityType
=
model
.
FindEntityType
(
typeof
(
Blog
))!;
var
property
=
entityType
.
FindProperty
(
nameof
(
Blog
.
RowVersion
))!;
Assert
.
Equal
(
"xmin"
,
property
.
GetColumnName
());
Assert
.
Equal
(
"xid"
,
property
.
GetColumnType
());
}
class
Blog
{
public
int
Id
{
get
;
set
;
}
[
Timestamp
]
public
uint
RowVersion
{
get
;
set
;
}
}
}
test/EFCore.PG.Tests/Metadata/Conventions/NpgsqlValueGenerationStrategyConventionTest.cs
浏览文件 @
7886196b
...
...
@@ -14,7 +14,6 @@ public void Annotations_are_added_when_conventional_model_builder_is_used()
var
annotations
=
model
.
GetAnnotations
().
OrderBy
(
a
=>
a
.
Name
).
ToList
();
Assert
.
Equal
(
3
,
annotations
.
Count
);
// TODO for PG9.6 testing: make this conditional
Assert
.
Equal
(
NpgsqlAnnotationNames
.
ValueGenerationStrategy
,
annotations
.
First
().
Name
);
Assert
.
Equal
(
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
,
annotations
.
First
().
Value
);
}
...
...
@@ -44,4 +43,4 @@ public void Annotations_are_added_when_conventional_model_builder_is_used_with_s
annotations
[
3
].
Name
);
Assert
.
NotNull
(
annotations
[
3
].
Value
);
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录