Skip to content

Commit 0947013

Browse files
committed
added Not to ElementPart - enables scenario like .Not.Nullable
1 parent 21cb167 commit 0947013

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/FluentNHibernate.Testing/FluentInterfaceTests/ElementPartTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ public void CanDeclareColumnNullable()
4444
ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping();
4545
var columnMappings = elementMapping.Columns.ToList();
4646
columnMappings.First().Nullable.ShouldEqual(true);
47-
47+
}
48+
49+
[Test]
50+
public void CanDeclareColumnNotNullable()
51+
{
52+
var part = new ElementPart(typeof(MappedObject));
53+
part.Column("nullabilityCheck");
54+
part.Not.Nullable();
55+
56+
ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping();
57+
var columnMappings = elementMapping.Columns.ToList();
58+
columnMappings.First().Nullable.ShouldEqual(false);
4859
}
4960
}
5061
}

src/FluentNHibernate/Mapping/ElementPart.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using FluentNHibernate.Mapping.Providers;
34
using FluentNHibernate.MappingModel;
45
using FluentNHibernate.MappingModel.Collections;
@@ -11,6 +12,7 @@ public class ElementPart : IElementMappingProvider
1112
readonly AttributeStore attributes = new AttributeStore();
1213
readonly AttributeStore columnAttributes = new AttributeStore();
1314
readonly ColumnMappingCollection<ElementPart> columns;
15+
bool nextBool = true;
1416

1517
public ElementPart(Type entity)
1618
{
@@ -71,14 +73,30 @@ public ElementPart Formula(string formula)
7173
/// </summary>
7274
public ElementPart Nullable()
7375
{
74-
columnAttributes.Set("NotNull", Layer.UserSupplied, false);
76+
columnAttributes.Set("NotNull", Layer.UserSupplied, !nextBool);
77+
nextBool = true;
7578
return this;
7679
}
7780

81+
/// <summary>
82+
/// Inverts the next boolean operation
83+
/// </summary>
84+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
85+
public ElementPart Not
86+
{
87+
get
88+
{
89+
nextBool = !nextBool;
90+
return this;
91+
}
92+
}
93+
7894
ElementMapping IElementMappingProvider.GetElementMapping()
7995
{
80-
var mapping = new ElementMapping(attributes.Clone());
81-
mapping.ContainingEntityType = entity;
96+
var mapping = new ElementMapping(attributes.Clone())
97+
{
98+
ContainingEntityType = entity
99+
};
82100

83101
foreach (var column in Columns)
84102
{

0 commit comments

Comments
 (0)