Skip to content

Commit 4c96c43

Browse files
committed
Added support for ChildWhere and ChildOrderBy on many-to-many mappings to be set via conventions
1 parent 8294f2a commit 4c96c43

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

src/FluentNHibernate.Testing/ConventionsTests/ApplyingToModel/HasManyToManyConventionTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public void ShouldSetChildForeignKeyProperty()
183183

184184
VerifyModel(x => ((ManyToManyMapping)x.Relationship).ForeignKey.ShouldEqual("xxx"));
185185
}
186+
187+
[Test]
188+
public void ShouldSetRelationshipWhereProperty()
189+
{
190+
Convention(x => x.Relationship.Where("where clause"));
191+
192+
VerifyModel(x => ((ManyToManyMapping)x.Relationship).Where.ShouldEqual("where clause"));
193+
}
194+
195+
[Test]
196+
public void ShouldSetOrderByProperty()
197+
{
198+
Convention(x => x.Relationship.OrderBy("order clause"));
199+
200+
VerifyModel(x => ((ManyToManyMapping)x.Relationship).OrderBy.ShouldEqual("order clause"));
201+
}
186202

187203
#region Helpers
188204

src/FluentNHibernate/Conventions/Inspections/IManyToManyInspector.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ public interface IManyToManyInspector : IRelationshipInspector
1313
bool LazyLoad { get; }
1414
NotFound NotFound { get; }
1515
Type ParentType { get; }
16+
17+
/// <summary>
18+
/// Applies to the joining table for this many-to-many.
19+
/// </summary>
1620
string Where { get; }
21+
22+
/// <summary>
23+
/// Applies to the joining table for this many-to-many.
24+
/// </summary>
25+
string OrderBy { get; }
1726
}
1827
}

src/FluentNHibernate/Conventions/Inspections/ManyToManyInspector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,9 @@ public string Where
8383
get { return mapping.Where; }
8484
}
8585

86-
}
86+
public string OrderBy
87+
{
88+
get { return mapping.OrderBy; }
89+
}
90+
}
8791
}

src/FluentNHibernate/Conventions/Instances/IManyToManyInstance.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@ public interface IManyToManyInstance : IManyToManyInspector, IRelationshipInstan
88
void Column(string columnName);
99
new IDefaultableEnumerable<IColumnInstance> Columns { get; }
1010
new void ForeignKey(string constraint);
11+
12+
/// <summary>
13+
/// Applies to the joining table for this many-to-many.
14+
/// </summary>
15+
new void Where(string where);
16+
17+
/// <summary>
18+
/// Applies to the joining table for this many-to-many.
19+
/// </summary>
20+
new void OrderBy(string orderBy);
1121
}
1222
}

src/FluentNHibernate/Conventions/Instances/ManyToManyInstance.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,20 @@ public void CustomClass(Type type)
5454

5555
public new void ForeignKey(string constraint)
5656
{
57-
if (!mapping.IsSpecified("ForeignKey"))
57+
if (!mapping.IsSpecified(x => x.ForeignKey))
5858
mapping.ForeignKey = constraint;
5959
}
60+
61+
public new void Where(string where)
62+
{
63+
if (!mapping.IsSpecified(x => x.Where))
64+
mapping.Where = where;
65+
}
66+
67+
public new void OrderBy(string orderBy)
68+
{
69+
if (!mapping.IsSpecified(x => x.OrderBy))
70+
mapping.OrderBy = orderBy;
71+
}
6072
}
6173
}

src/FluentNHibernate/MappingModel/Collections/ManyToManyMapping.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public override bool IsSpecified(string property)
134134
return attributes.IsSpecified(property);
135135
}
136136

137+
public bool IsSpecified<TResult>(Expression<Func<ManyToManyMapping, TResult>> property)
138+
{
139+
return attributes.IsSpecified(property);
140+
}
141+
137142
public bool HasValue<TResult>(Expression<Func<ManyToManyMapping, TResult>> property)
138143
{
139144
return attributes.HasValue(property);

0 commit comments

Comments
 (0)