Skip to content

Commit 408fb8b

Browse files
committed
Merge pull request #94 from firo222/master
fixed: cant change from bag to list in convention
2 parents c546ebe + bf983fd commit 408fb8b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,19 @@ public void ShouldSetTableNameProperty()
199199

200200
VerifyModel(x => x.TableName.ShouldEqual("xxx"));
201201
}
202+
203+
[Test]
204+
public void ShouldChangeCollectionTypeToList()
205+
{
206+
Convention(x => { x.AsList(); x.Index.Column("position"); } );
202207

208+
VerifyModel(x =>
209+
{
210+
x.Collection.ShouldEqual(Collection.List);
211+
x.Index.ShouldNotBeNull(); // a list without index will result in wrong xml
212+
});
213+
}
214+
203215
#region Helpers
204216

205217
private void Convention(Action<ICollectionInstance> convention)

src/FluentNHibernate/Conventions/Instances/CollectionInstance.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ void ICollectionInstance.AsBag()
173173
void ICollectionInstance.AsList()
174174
{
175175
mapping.Collection = Collection.List;
176+
if (mapping.Index == null)
177+
{
178+
var indexMapping = new IndexMapping();
179+
var columnMapping = new ColumnMapping();
180+
columnMapping.Set(x => x.Name, Layer.Defaults, "Index");
181+
indexMapping.AddColumn(Layer.Defaults, columnMapping);
182+
mapping.Set(x => x.Index, Layer.Defaults, indexMapping);
183+
};
176184
}
177185

178186
void ICollectionInstance.AsMap()

src/FluentNHibernate/Conventions/Instances/ColumnInstance.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,15 @@ public ColumnInstance(Type parentType, ColumnMapping mapping)
1818
{
1919
mapping.Set(x => x.Length, Layer.Conventions, length);
2020
}
21+
22+
public new void Index(string indexname)
23+
{
24+
mapping.Set(x => x.Index, Layer.Conventions, indexname);
25+
}
26+
27+
public new void Default(string defaultvalue)
28+
{
29+
mapping.Set(x => x.Default, Layer.Conventions, defaultvalue);
30+
}
2131
}
2232
}

src/FluentNHibernate/Conventions/Instances/IColumnInstance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ namespace FluentNHibernate.Conventions.Instances
55
public interface IColumnInstance : IColumnInspector
66
{
77
new void Length(int length);
8+
new void Index(string indexname);
9+
new void Default(string defaultvalue);
810
}
911
}

0 commit comments

Comments
 (0)