Skip to content

Commit 4d2348d

Browse files
committed
Merge pull request #267 from Micha-kun/master
Fix for bug #231
2 parents 5101705 + 3ab2f59 commit 4d2348d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,14 @@ public void ShouldWriteLengthAttribute()
6464

6565
testHelper.VerifyAll(writer);
6666
}
67+
68+
[Test(Description = "Bug #231 :: Bug when trying to change varchar length for CompositeId")]
69+
public void WhenKeyPropertyMappingContainsLengthAndCustomColumnLengthAttributeIsRenderedIntoColumnElement()
70+
{
71+
var keyPropertyMapping = new KeyPropertyMapping();
72+
keyPropertyMapping.Set(propertyMapping => propertyMapping.Length, Layer.Defaults, 2);
73+
keyPropertyMapping.AddColumn(new ColumnMapping());
74+
writer.VerifyXml(keyPropertyMapping).DoesntHaveAttribute("length").Element("column").HasAttribute("length", "2");
75+
}
6776
}
6877
}

src/FluentNHibernate/MappingModel/Output/XmlKeyPropertyWriter.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Xml;
34
using FluentNHibernate.MappingModel.Identity;
45
using FluentNHibernate.Utils;
@@ -39,7 +40,19 @@ public override void ProcessKeyProperty(KeyPropertyMapping mapping)
3940
element.WithAtt("type", mapping.Type);
4041

4142
if (mapping.IsSpecified("Length"))
42-
element.WithAtt("length", mapping.Length);
43+
{
44+
if (mapping.Columns.Any())
45+
{
46+
foreach (var columnMapping in mapping.Columns.Where(column => !column.IsSpecified("Length")))
47+
{
48+
columnMapping.Set(map => map.Length, Layer.Defaults, mapping.Length);
49+
}
50+
}
51+
else
52+
{
53+
element.WithAtt("length", mapping.Length);
54+
}
55+
}
4356
}
4457

4558
public override void Visit(ColumnMapping columnMapping)

0 commit comments

Comments
 (0)