Skip to content

Commit 1754fa3

Browse files
committed
Merge pull request #186 from chester89/investigating-110
I think this one should close both #110 and #194
2 parents 0947013 + 262e78a commit 1754fa3

File tree

5 files changed

+96
-9
lines changed

5 files changed

+96
-9
lines changed

src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public class when_subclass_map_has_a_has_many_to_another_entity
3939
model.Add(new SpecialProductMap());
4040
model.Add(new OptionMap());
4141

42-
cfg = new Configuration();
43-
SQLiteConfiguration.Standard.InMemory()
44-
.ConfigureProperties(cfg);
45-
model.Configure(cfg);
42+
//cfg = new Configuration();
43+
//SQLiteConfiguration.Standard.InMemory()
44+
// .ConfigureProperties(cfg);
45+
//model.Configure(cfg);
4646

47-
new SchemaExport(cfg).Create(true, false);
47+
//new SchemaExport(cfg).Create(true, false);
4848
};
4949

5050
Because of = () =>

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Linq;
23
using FluentNHibernate.Mapping;
4+
using FluentNHibernate.Mapping.Providers;
5+
using FluentNHibernate.MappingModel.ClassBased;
36
using NUnit.Framework;
47

58
namespace FluentNHibernate.Testing.DomainModel.Mapping
@@ -160,6 +163,25 @@ public void MixedKeyPropertyAndManyToOneOrdering()
160163
.HasName("key-property");
161164
}
162165

166+
[Test]
167+
public void CompositeIdWithSubclass()
168+
{
169+
new MappingTester<CompIdTarget>()
170+
.SubClassMapping<ComIdSubclass>(s =>
171+
{
172+
s.Table("subclasstable");
173+
s.KeyColumn("subclass_longId");
174+
s.KeyColumn("subclass_nullablelongId");
175+
})
176+
.ForMapping(c => c.CompositeId()
177+
.KeyProperty(x => x.LongId)
178+
.KeyProperty(x => x.NullableLongId))
179+
.Element("class/joined-subclass/key/*[1]")
180+
.Exists().HasName("column").HasAttribute("name", "subclass_longId")
181+
.RootElement.Element("class/joined-subclass/key/*[2]")
182+
.Exists().HasName("column").HasAttribute("name", "subclass_nullablelongId");
183+
}
184+
163185
public class CompIdTarget
164186
{
165187
public virtual long LongId { get; set; }
@@ -170,6 +192,11 @@ public class CompIdTarget
170192
public virtual SomeEnum EnumProperty { get; set; }
171193
}
172194

195+
public class ComIdSubclass : CompIdTarget
196+
{
197+
198+
}
199+
173200
public enum SomeEnum
174201
{}
175202

@@ -183,5 +210,12 @@ public class ComponentKey
183210
public virtual int KeyCol1 { get; set; }
184211
public virtual int KeyCol2 { get; set; }
185212
}
213+
214+
[Test]
215+
public void Can_Have_Multiple_key_Columns()
216+
{
217+
var provider = (IIndeterminateSubclassMappingProvider)new MultipleKeyColumnsTester.TestMap();
218+
provider.GetSubclassMapping(SubclassType.JoinedSubclass).Key.Columns.Count().ShouldEqual(2);
219+
}
186220
}
187221
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using FluentNHibernate.Mapping;
6+
using FluentNHibernate.Mapping.Providers;
7+
using FluentNHibernate.MappingModel.ClassBased;
8+
using NUnit.Framework;
9+
10+
namespace FluentNHibernate.Testing.DomainModel.Mapping
11+
{
12+
[TestFixture]
13+
public class MultipleKeyColumnsTester
14+
{
15+
[Test]
16+
public void CanHaveMultipleKeyColumns()
17+
{
18+
var provider = (IIndeterminateSubclassMappingProvider)new TestMap();
19+
provider.GetSubclassMapping(SubclassType.JoinedSubclass).Key.Columns.Count().ShouldEqual(2);
20+
}
21+
22+
public class Base
23+
{
24+
public int Id { get; set; }
25+
}
26+
27+
public class TestMap : SubclassMap<Base>
28+
{
29+
public TestMap()
30+
{
31+
KeyColumn("col1");
32+
KeyColumn("col2");
33+
}
34+
}
35+
}
36+
}

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="AutoMapping\Overrides\CompositeIdOverrides.cs" />
125125
<Compile Include="AutoMapping\Overrides\HibernateMappingOverrides.cs" />
126126
<Compile Include="DomainModel\Mapping\ManyToManySelfReferencedInverseIntegrationTester.cs" />
127+
<Compile Include="DomainModel\Mapping\MultipleKeyColumnsTester.cs" />
127128
<Compile Include="DomainModel\MemberAccessResolverTests.cs" />
128129
<Compile Include="DomainModel\MemberBackingFieldTests.cs" />
129130
<Compile Include="DomainModel\NamingTests.cs" />

src/FluentNHibernate/MappingModel/Collections/AttributeLayeredValues.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
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;
12+
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+
}
1124

1225
public LayeredValues this[string attribute]
1326
{
1427
get
1528
{
1629
EnsureValueExists(attribute);
17-
1830
return inner[attribute];
1931
}
2032
}
@@ -83,12 +95,16 @@ public override int GetHashCode()
8395

8496
pairCode += pair.Key.GetHashCode();
8597
pairCode += pair.Value.GetHashCode();
86-
8798
hashCode += pairCode ^ 367;
8899
}
89100
}
90101

91102
return hashCode;
92103
}
104+
105+
public void GetObjectData(SerializationInfo info, StreamingContext context)
106+
{
107+
info.AddValue("inner", inner);
108+
}
93109
}
94110
}

0 commit comments

Comments
 (0)