Skip to content

Commit d624aa9

Browse files
committed
Registers changed tuple for following persist
1 parent e9af9de commit d624aa9

File tree

3 files changed

+327
-271
lines changed

3 files changed

+327
-271
lines changed

Orm/Xtensive.Orm/Orm/Persistent.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2007-2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Dmitri Maximov
55
// Created: 2007.08.03
66

@@ -273,32 +273,57 @@ protected internal Key GetReferenceKey(FieldInfo field)
273273

274274
protected internal void SetReferenceKey(FieldInfo field, Key value)
275275
{
276+
if (Session.StorageNodeId != value.NodeId) {
277+
throw new ArgumentException(Strings.ExKeyBelongsToDifferentStorageNode, "value");
278+
}
279+
280+
// KeyRemapper also uses this method during persist so we need to detect whether it is KeyRemapper
281+
var isPersisting = Session.IsPersisting;
276282
Key oldValue = null;
277283
try {
278284
oldValue = GetReferenceKey(field);
279-
if (field.ReflectedType.IsInterface)
285+
if (field.ReflectedType.IsInterface) {
280286
field = TypeInfo.FieldMap[field];
287+
}
288+
281289
SystemBeforeSetValue(field, value);
282-
if (!field.IsEntity)
290+
if (!field.IsEntity) {
283291
throw new InvalidOperationException(
284-
String.Format(Strings.ExFieldIsNotAnEntityField, field.Name, field.ReflectedType.Name));
292+
string.Format(Strings.ExFieldIsNotAnEntityField, field.Name, field.ReflectedType.Name));
293+
}
294+
295+
if (!isPersisting) { SystemBeforeTupleChange(); }
285296

286297
var types = Session.Domain.Model.Types;
287298
if (value == null) {
288-
for (int i = 0; i < field.MappingInfo.Length; i++)
299+
for (var i = 0; i < field.MappingInfo.Length; i++) {
289300
Tuple.SetValue(field.MappingInfo.Offset + i, null);
301+
}
302+
303+
if (!isPersisting) { SystemTupleChange(); }
290304
return;
291305
}
292-
if (!field.ValueType.IsAssignableFrom(value.TypeInfo.UnderlyingType))
306+
if (!field.ValueType.IsAssignableFrom(value.TypeInfo.UnderlyingType)) {
293307
throw new InvalidOperationException(string.Format("Key of {0} type is not assignable to field of {1} type", value.TypeInfo.Name, field.ValueType.Name));
308+
}
309+
310+
if (value == oldValue) {
311+
return;
312+
}
294313

295314
value.Value.CopyTo(Tuple, 0, field.MappingInfo.Offset, field.MappingInfo.Length);
296-
if (field.IsPrimaryKey)
297-
value.Value.CopyTo(((Entity)this).Key.Value, 0, field.MappingInfo.Offset, field.MappingInfo.Length);
315+
if (field.IsPrimaryKey) {
316+
value.Value.CopyTo(((Entity) this).Key.Value, 0, field.MappingInfo.Offset, field.MappingInfo.Length);
317+
}
318+
319+
if (!isPersisting) {
320+
SystemTupleChange();
321+
}
322+
298323
SystemSetValue(field, oldValue, value);
299324
SystemSetValueCompleted(field, oldValue, value, null);
300325
}
301-
catch(Exception e) {
326+
catch (Exception e) {
302327
SystemSetValueCompleted(field, oldValue, value, e);
303328
throw;
304329
}

Orm/Xtensive.Orm/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)