Skip to content

Commit ae3f056

Browse files
committed
NH-2779 - Fix possible InvalidCastException for un-fetched properties and unknown back-refs.
1 parent c09b595 commit ae3f056

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/NHibernate/Impl/Printer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33

44
using NHibernate.Engine;
5+
using NHibernate.Intercept;
56
using NHibernate.Metadata;
7+
using NHibernate.Properties;
68
using NHibernate.Type;
79
using NHibernate.Util;
810

@@ -41,7 +43,15 @@ public string ToString(object entity, EntityMode entityMode)
4143

4244
for (int i = 0; i < types.Length; i++)
4345
{
44-
result[names[i]] = types[i].ToLoggableString(values[i], _factory);
46+
var value = values[i];
47+
if (Equals(LazyPropertyInitializer.UnfetchedProperty, value) || Equals(BackrefPropertyAccessor.Unknown, value))
48+
{
49+
result[names[i]] = value.ToString();
50+
}
51+
else
52+
{
53+
result[names[i]] = types[i].ToLoggableString(value, _factory);
54+
}
4555
}
4656

4757
return cm.EntityName + CollectionPrinter.ToString(result);

0 commit comments

Comments
 (0)