Skip to content

Commit 81707dc

Browse files
committed
修复数据引擎处理带值的 Sequence 字段依然生成序列号的问题。 💺
1 parent fabcd41 commit 81707dc

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Zongsoft.Data/src/Common/DataImporterBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public object GetValue(ref object target)
126126
if(CanSequence(property.Sequence))
127127
{
128128
//获取目标的当前属性值,如果获取失败或其值为空或数字零,则递增该字段序号
129-
if(!Reflection.Reflector.TryGetValue(this.Info, ref target, out value) || value == null || Zongsoft.Common.Convert.IsZero(value))
129+
if(!Reflection.Reflector.TryGetValue(this.Info, ref target, out value) || value == null || Convert.IsDBNull(value) || Zongsoft.Common.Convert.IsZero(value))
130130
{
131131
//递增当前属性对应的序号
132132
var id = _context.DataAccess.Sequencer.Increase(property);

Zongsoft.Data/src/Common/Expressions/StatementExtension.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ private static List<FieldIdentifier> GetSequenceFields(IStatementBase statement)
270270
return result;
271271
}
272272

273+
private static bool CanSequence(IDataMutateOptions options, object value) => options switch
274+
{
275+
IDataInsertOptions insertion when insertion.SequenceSuppressed => value == null || Convert.IsDBNull(value),
276+
IDataUpsertOptions upsertion when upsertion.SequenceSuppressed => value == null || Convert.IsDBNull(value),
277+
_ => value == null || Convert.IsDBNull(value) || Zongsoft.Common.Convert.IsZero(value),
278+
};
279+
273280
private static void SetSequenceValue(IDataMutateContextBase context, IEnumerable<FieldIdentifier> sequenceFileds , object data)
274281
{
275282
if(data == null || sequenceFileds == null)
@@ -285,7 +292,7 @@ private static void SetSequenceValue(IDataMutateContextBase context, IEnumerable
285292
{
286293
var value = field.Token.GetValue(data);
287294

288-
if(value == null || Convert.IsDBNull(value) || object.Equals(value, Zongsoft.Common.TypeExtension.GetDefaultValue(field.Token.MemberType)) || (context.Options is IDataInsertOptions options && !options.SequenceSuppressed))
295+
if(CanSequence(context.Options, value))
289296
{
290297
var id = ((DataAccess)context.DataAccess).Increase(context, sequence, data);
291298
field.Token.SetValue(ref data, Convert.ChangeType(id, field.Token.MemberType));
@@ -310,7 +317,7 @@ private static async ValueTask SetSequenceValueAsync(IDataMutateContextBase cont
310317
{
311318
var value = field.Token.GetValue(data);
312319

313-
if(value == null || Convert.IsDBNull(value) || object.Equals(value, Zongsoft.Common.TypeExtension.GetDefaultValue(field.Token.MemberType)) || (context.Options is IDataInsertOptions options && !options.SequenceSuppressed))
320+
if(CanSequence(context.Options, value))
314321
{
315322
var id = await ((DataAccess)context.DataAccess).IncreaseAsync(context, sequence, data, cancellation);
316323
field.Token.SetValue(ref data, Convert.ChangeType(id, field.Token.MemberType));

Zongsoft.Data/src/Zongsoft.Data.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>7.18.1</Version>
3+
<Version>7.18.2</Version>
44
<Product>Zongsoft Data Library</Product>
55
<Description>This is an Object/Relational Mapping(ORM) data engine.</Description>
66
<RootNamespace>Zongsoft.Data</RootNamespace>

0 commit comments

Comments
 (0)