Skip to content

Commit 4421b05

Browse files
committed
Merge pull request #188 from W1N9Zr0/master
Fix exception when mapping nested generic classes
2 parents 1754fa3 + 748847a commit 4421b05

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/FluentNHibernate.Testing/DomainModel/Mapping/PropertyPartTester.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,18 @@ public void CanSpecifyNotUpdate()
441441
.Element("class/property").HasAttribute("update", "false");
442442
}
443443

444+
[Test]
445+
public void MapNestedGeneric()
446+
{
447+
new MappingTester<OuterTarget<String>.NestedTarget>()
448+
.ForMapping(m =>
449+
{
450+
m.Id(x => x.Id);
451+
m.Map(x => x.Value);
452+
})
453+
.Element("class").HasAttribute("table", "`NestedTarget_String`");
454+
}
455+
444456
#region Custom IUserType impl for testing
445457
public class CustomTypeForTesting : IUserType
446458
{
@@ -609,6 +621,15 @@ public class ComponentTarget
609621
public object Name { get; set; }
610622
}
611623

624+
class OuterTarget<T>
625+
{
626+
public class NestedTarget
627+
{
628+
public virtual int Id { get; set; }
629+
public virtual T Value { get; set; }
630+
}
631+
}
632+
612633
public class FakePropertyAccessor : IPropertyAccessor
613634
{
614635
public IGetter GetGetter(Type theClass, string propertyName)

src/FluentNHibernate/Mapping/ClassMap.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,11 @@ string GetDefaultTableName()
691691
if (EntityType.IsGenericType)
692692
{
693693
// special case for generics: GenericType_GenericParameterType
694-
tableName = EntityType.Name.Substring(0, EntityType.Name.IndexOf('`'));
694+
var genericQuoteIndex = EntityType.Name.IndexOf('`');
695+
if (genericQuoteIndex >= 0)
696+
{
697+
tableName = EntityType.Name.Substring(0, genericQuoteIndex);
698+
} // else generic declaration not directly in this class
695699

696700
foreach (var argument in EntityType.GetGenericArguments())
697701
{

0 commit comments

Comments
 (0)