Skip to content

Commit 1f12d0f

Browse files
committed
fix: Extensions.DeepCopy broken for classes containing AttributeLayeredValues
while deserializing a hashset containing AttributeLayeredValues AttributeLayeredValues.ContentEquals is broken because the content isnt deserialised which results in all values of the Hashset being collapsed to one.
1 parent dbbdb3f commit 1f12d0f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/FluentNHibernate.Testing/DomainModel/Mapping/CompositeIdentityPartTester.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ public void MixedKeyPropertyAndManyToOneOrdering()
159159
.RootElement.Element("class/composite-id/*[2]")
160160
.HasName("key-property");
161161
}
162+
163+
[Test]
164+
public void CompositeIdWithSubclass()
165+
{
166+
new MappingTester<CompIdTarget>()
167+
.SubClassMapping<ComIdSubclass>(s =>
168+
{
169+
s.Table("subclasstable");
170+
s.KeyColumn("subclass_longId");
171+
s.KeyColumn("subclass_nullablelongId");
172+
})
173+
.ForMapping(c => c.CompositeId()
174+
.KeyProperty(x => x.LongId)
175+
.KeyProperty(x => x.NullableLongId))
176+
.Element("class/joined-subclass/key/*[1]")
177+
.Exists().HasName("column").HasAttribute("name", "subclass_longId")
178+
.RootElement.Element("class/joined-subclass/key/*[2]")
179+
.Exists().HasName("column").HasAttribute("name", "subclass_nullablelongId")
180+
;
181+
}
162182

163183
public class CompIdTarget
164184
{
@@ -183,5 +203,10 @@ public class ComponentKey
183203
public virtual int KeyCol1 { get; set; }
184204
public virtual int KeyCol2 { get; set; }
185205
}
206+
207+
public class ComIdSubclass : CompIdTarget
208+
{
209+
210+
}
186211
}
187212
}

src/FluentNHibernate/MappingModel/Collections/AttributeLayeredValues.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.Serialization;
45

56
namespace FluentNHibernate.MappingModel.Collections
67
{
78
[Serializable]
8-
public class AttributeLayeredValues
9+
public class AttributeLayeredValues : ISerializable
910
{
10-
readonly Dictionary<string, LayeredValues> inner = new Dictionary<string, LayeredValues>();
11+
readonly Dictionary<string, LayeredValues> inner;
1112

13+
public AttributeLayeredValues()
14+
{
15+
inner = new Dictionary<string, LayeredValues>();
16+
}
17+
18+
public AttributeLayeredValues(SerializationInfo info, StreamingContext context)
19+
{
20+
inner = (Dictionary<string, LayeredValues>)info
21+
.GetValue("inner", typeof(Dictionary<string, LayeredValues>));
22+
inner.OnDeserialization(this);
23+
}
24+
1225
public LayeredValues this[string attribute]
1326
{
1427
get
@@ -90,5 +103,10 @@ public override int GetHashCode()
90103

91104
return hashCode;
92105
}
106+
107+
public void GetObjectData(SerializationInfo info, StreamingContext context)
108+
{
109+
info.AddValue("inner", inner);
110+
}
93111
}
94112
}

0 commit comments

Comments
 (0)