Skip to content

Commit 71ec500

Browse files
committed
FIX: #205 - Can't specify length for element
1 parent 61337c7 commit 71ec500

File tree

8 files changed

+22
-34
lines changed

8 files changed

+22
-34
lines changed

src/FluentNHibernate.Testing/ConventionsTests/Inspection/ElementInspectorMapsToElementMapping.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,20 @@ public void FormulaIsNotSet()
9292
[Test]
9393
public void LengthMapped()
9494
{
95-
mapping.Length = 50;
95+
mapping.AddColumn(new ColumnMapping
96+
{
97+
Length = 50
98+
});
9699
inspector.Length.ShouldEqual(50);
97100
}
98101

99-
[Test]
102+
[Test, Ignore("This isn't going to work very well...")]
100103
public void LengthIsSet()
101104
{
102-
mapping.Length = 50;
105+
mapping.AddColumn(new ColumnMapping
106+
{
107+
Length = 50
108+
});
103109
inspector.IsSet(Prop(x => x.Length))
104110
.ShouldBeTrue();
105111
}

src/FluentNHibernate.Testing/FluentInterfaceTests/ElementPartTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ public class ElementPartTests
1717
public void CanSetLength()
1818
{
1919
var part = new ElementPart(typeof(MappedObject));
20+
part.Column("test");
2021
part.Length(50);
2122

2223
ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping();
23-
elementMapping.Length.ShouldEqual(50);
24+
elementMapping.Columns.First().Length.ShouldEqual(50);
2425
}
2526

2627
[Test]

src/FluentNHibernate.Testing/MappingModel/Equality/MappingEqualitySpecs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ public override ElementMapping create_mapping()
351351
{
352352
ContainingEntityType = typeof(Target),
353353
Formula = "formula",
354-
Length = 1,
355354
Type = new TypeReference(typeof(Target))
356355
};
357356

src/FluentNHibernate.Testing/MappingModel/Output/XmlElementWriterTester.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ public void ShouldWriteColumns()
3838
.Element("column").Exists();
3939
}
4040

41-
[Test]
42-
public void ShouldWriteLength()
43-
{
44-
var testHelper = new XmlWriterTestHelper<ElementMapping>();
45-
testHelper.Check(x => x.Length, 50).MapsToAttribute("length");
46-
47-
testHelper.VerifyAll(writer);
48-
}
49-
5041
[Test]
5142
public void ShouldWriteFormula()
5243
{

src/FluentNHibernate/Conventions/Inspections/ElementInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public string Formula
5454

5555
public int Length
5656
{
57-
get { return mapping.Length; }
57+
get { return mapping.Columns.Select(x => x.Length).FirstOrDefault(); }
5858
}
5959
}
6060
}

src/FluentNHibernate/Mapping/ElementPart.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ namespace FluentNHibernate.Mapping
77
{
88
public class ElementPart : IElementMappingProvider
99
{
10-
private readonly Type entity;
11-
private readonly AttributeStore<ElementMapping> attributes = new AttributeStore<ElementMapping>();
12-
private readonly ColumnMappingCollection<ElementPart> columns;
10+
Type entity;
11+
AttributeStore<ElementMapping> attributes = new AttributeStore<ElementMapping>();
12+
AttributeStore<ColumnMapping> columnAttributes = new AttributeStore<ColumnMapping>();
1313

1414
public ElementPart(Type entity)
1515
{
1616
this.entity = entity;
17-
columns = new ColumnMappingCollection<ElementPart>(this);
17+
Columns = new ColumnMappingCollection<ElementPart>(this);
1818
}
1919

2020
/// <summary>
@@ -23,17 +23,14 @@ public ElementPart(Type entity)
2323
/// <param name="elementColumnName">Column name</param>
2424
public ElementPart Column(string elementColumnName)
2525
{
26-
columns.Add(elementColumnName);
26+
Columns.Add(elementColumnName);
2727
return this;
2828
}
2929

3030
/// <summary>
3131
/// Modify the columns for this element
3232
/// </summary>
33-
public ColumnMappingCollection<ElementPart> Columns
34-
{
35-
get { return columns; }
36-
}
33+
public ColumnMappingCollection<ElementPart> Columns { get; private set; }
3734

3835
/// <summary>
3936
/// Specify the element type
@@ -51,7 +48,7 @@ public ElementPart Type<TElement>()
5148
/// <param name="length">Column length</param>
5249
public ElementPart Length(int length)
5350
{
54-
attributes.Set(x => x.Length, length);
51+
columnAttributes.Set(x => x.Length, length);
5552
return this;
5653
}
5754

@@ -71,7 +68,10 @@ ElementMapping IElementMappingProvider.GetElementMapping()
7168
mapping.ContainingEntityType = entity;
7269

7370
foreach (var column in Columns)
71+
{
72+
column.MergeAttributes(columnAttributes);
7473
mapping.AddColumn(column);
74+
}
7575

7676
return mapping;
7777
}

src/FluentNHibernate/MappingModel/Collections/ElementMapping.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ public string Formula
4141
set { attributes.Set(x => x.Formula, value); }
4242
}
4343

44-
public int Length
45-
{
46-
get { return attributes.Get(x => x.Length); }
47-
set { attributes.Set(x => x.Length, value); }
48-
}
49-
5044
public void AddColumn(ColumnMapping mapping)
5145
{
5246
columns.Add(mapping);

src/FluentNHibernate/MappingModel/Output/XmlElementWriter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ public override void ProcessElement(ElementMapping mapping)
3131
if (mapping.HasValue(x => x.Type))
3232
element.WithAtt("type", mapping.Type);
3333

34-
if (mapping.HasValue(x => x.Length))
35-
element.WithAtt("length", mapping.Length);
36-
3734
if (mapping.HasValue(x => x.Formula))
3835
element.WithAtt("formula", mapping.Formula);
3936
}

0 commit comments

Comments
 (0)