Skip to content

Commit 090117e

Browse files
committed
Merge pull request #100 from hazzik/one-to-many-OtherSide
Added OtherSide property to one-to-many
2 parents bda9e19 + 1637830 commit 090117e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/FluentNHibernate/Conventions/Inspections/IOneToManyCollectionInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ namespace FluentNHibernate.Conventions.Inspections
33
public interface IOneToManyCollectionInspector : ICollectionInspector
44
{
55
new IOneToManyInspector Relationship { get; }
6+
7+
IManyToOneInspector OtherSide { get; }
68
}
79
}

src/FluentNHibernate/Conventions/Instances/IOneToManyCollectionInstance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public interface IOneToManyCollectionInstance : IOneToManyCollectionInspector, I
1111
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
1212
new IOneToManyCollectionInstance Not { get; }
1313

14+
new IManyToOneInstance OtherSide { get; }
15+
1416
/// <summary>
1517
/// Applies a filter to this relationship given its name.
1618
/// </summary>

src/FluentNHibernate/Conventions/Instances/ManyToManyCollectionInstance.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ public IManyToManyCollectionInstance OtherSide
3535
{
3636
get
3737
{
38-
if (mapping.OtherSide == null || !(mapping.OtherSide is CollectionMapping))
38+
var otherSide = mapping.OtherSide as CollectionMapping;
39+
if (otherSide == null)
3940
return null;
4041

41-
return new ManyToManyCollectionInstance((CollectionMapping)mapping.OtherSide);
42+
return new ManyToManyCollectionInstance(otherSide);
4243
}
4344
}
4445

4546
public new IManyToManyInstance Relationship
4647
{
4748
get { return new ManyToManyInstance((ManyToManyMapping)mapping.Relationship); }
4849
}
50+
4951
public new Type ChildType
5052
{
5153
get { return mapping.ChildType; }

src/FluentNHibernate/Conventions/Instances/OneToManyCollectionInstance.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using FluentNHibernate.Conventions.Inspections;
3+
using FluentNHibernate.MappingModel;
34
using FluentNHibernate.MappingModel.Collections;
45

56
namespace FluentNHibernate.Conventions.Instances
@@ -20,6 +21,23 @@ IOneToManyInspector IOneToManyCollectionInspector.Relationship
2021
get { return Relationship; }
2122
}
2223

24+
IManyToOneInspector IOneToManyCollectionInspector.OtherSide
25+
{
26+
get { return OtherSide; }
27+
}
28+
29+
public IManyToOneInstance OtherSide
30+
{
31+
get
32+
{
33+
var otherSide = mapping.OtherSide as ManyToOneMapping;
34+
if (otherSide == null)
35+
return null;
36+
37+
return new ManyToOneInstance(otherSide);
38+
}
39+
}
40+
2341
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
2442
public new IOneToManyCollectionInstance Not
2543
{

0 commit comments

Comments
 (0)