Skip to content

Commit b359650

Browse files
committed
Adding appropriate alert for non auto prop ghost property
SVN: trunk@4933
1 parent 63ab5b7 commit b359650

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System.Collections;
22
using NHibernate.ByteCode.Castle;
33
using NHibernate.Cfg;
4+
using NHibernate.Tuple.Entity;
45
using NUnit.Framework;
56

67
namespace NHibernate.Test.GhostProperty
78
{
89
[TestFixture]
910
public class GhostPropertyFixture : TestCase
1011
{
12+
private string log;
13+
1114
protected override string MappingsAssembly
1215
{
1316
get { return "NHibernate.Test"; }
@@ -55,6 +58,21 @@ protected override void OnTearDown()
5558
}
5659
}
5760

61+
protected override void BuildSessionFactory()
62+
{
63+
using (var logSpy = new LogSpy(typeof(EntityMetamodel)))
64+
{
65+
base.BuildSessionFactory();
66+
log = logSpy.GetWholeLog();
67+
}
68+
}
69+
70+
[Test]
71+
public void ShouldGenerateErrorForNonAutoPropGhostProp()
72+
{
73+
Assert.IsTrue(log.Contains("Lazy or ghost property NHibernate.Test.GhostProperty.Order.Payment is not an auto property, which may result in uninitialized property access"));
74+
}
75+
5876
[Test]
5977
public void CanGetActualValueFromLazyManyToOne()
6078
{

src/NHibernate.Test/GhostProperty/Order.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
public class Order
44
{
55
public virtual int Id { get; set; }
6-
public virtual Payment Payment { get; set; }
6+
private Payment payment;
7+
8+
public virtual Payment Payment
9+
{
10+
get { return payment; }
11+
set { payment = value; }
12+
}
713
}
814

915
public abstract class Payment

src/NHibernate/Tuple/Entity/EntityMetamodel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ private static void VerifyCanInterceptPropertiesForLazyOrGhostProperties(Persist
303303
{
304304
foreach (var prop in persistentClass.PropertyClosureIterator)
305305
{
306-
if (prop.IsLazy == false && prop.UnwrapProxy)
306+
if (prop.IsLazy == false &&
307+
prop.UnwrapProxy == false)
307308
continue;
308309

309310
var getter = prop.GetGetter(persistentClass.MappedClass);

0 commit comments

Comments
 (0)