Skip to content

Commit 102240e

Browse files
committed
If no base type is discernable (or can't be pulled from the Extends<T>() option), then don't set a default key mapping
1 parent 9ab7970 commit 102240e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/FluentNHibernate.Testing/PersistenceModelTests/SubclassPersistenceModelTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ public class TPTWI_TopSubclassMap
483483
{
484484
public TPTWI_TopSubclassMap()
485485
{
486+
Extends<TPTWI_ITop>();
486487
KeyColumn("Id");
487488
}
488489
}

src/FluentNHibernate/Mapping/SubclassMap.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,16 @@ SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(Subclas
292292
attributes.Set("DiscriminatorValue", Layer.Defaults, typeof(T).Name);
293293

294294
// TODO: un-hardcode this
295-
var key = new KeyMapping();
296-
key.AddColumn(Layer.Defaults, new ColumnMapping(typeof(T).BaseType.Name + "_id"));
295+
Type baseType = typeof(T).BaseType
296+
?? attributes.Get("Extends") as Type;
297+
if (baseType != null)
298+
{
299+
var key = new KeyMapping();
300+
key.AddColumn(Layer.Defaults, new ColumnMapping(baseType.Name + "_id"));
301+
attributes.Set("Key", Layer.Defaults, key);
302+
}
297303

298304
attributes.Set("TableName", Layer.Defaults, GetDefaultTableName());
299-
attributes.Set("Key", Layer.Defaults, key);
300305

301306
// TODO: this is nasty, we should find a better way
302307
mapping.OverrideAttributes(attributes.Clone());

0 commit comments

Comments
 (0)