Skip to content

Commit 213ace3

Browse files
committed
Added ability to set key as (not)nullable via convention
1 parent c24de5a commit 213ace3

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ public void ShouldSetPropertyRefProperty()
192192
VerifyModel(x => x.Key.PropertyRef.ShouldEqual("xxx"));
193193
}
194194

195+
[Test]
196+
public void KeyNullableShouldSetModelValue()
197+
{
198+
Convention(x => x.KeyNullable());
199+
200+
VerifyModel(x => x.Key.NotNull.ShouldBeFalse());
201+
}
202+
203+
[Test]
204+
public void KeyNotNullableShouldSetModelValue()
205+
{
206+
Convention(x => x.Not.KeyNullable());
207+
208+
VerifyModel(x => x.Key.NotNull.ShouldBeTrue());
209+
}
210+
195211
[Test]
196212
public void ShouldSetTableNameProperty()
197213
{

src/FluentNHibernate/Conventions/Instances/CollectionInstance.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ public void Subselect(string subselect)
122122
mapping.Set(x => x.Subselect, Layer.Conventions, subselect);
123123
}
124124

125+
public void KeyNullable()
126+
{
127+
mapping.Key.Set(x => x.NotNull, Layer.Conventions, !nextBool);
128+
nextBool = true;
129+
}
130+
125131
public void Table(string tableName)
126132
{
127133
mapping.Set(x => x.TableName, Layer.Conventions, tableName);

src/FluentNHibernate/Conventions/Instances/ICollectionInstance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ public interface ICollectionInstance : ICollectionInspector
4343
new void OrderBy(string orderBy);
4444
new void Sort(string sort);
4545
void Subselect(string subselect);
46+
void KeyNullable();
4647
}
4748
}

0 commit comments

Comments
 (0)