|
From: <aye...@us...> - 2010-01-24 17:42:07
|
Revision: 4924
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4924&view=rev
Author: ayenderahien
Date: 2010-01-24 17:41:59 +0000 (Sun, 24 Jan 2010)
Log Message:
-----------
Adding error in the log about not using auto prop
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2010-01-24 16:46:51 UTC (rev 4923)
+++ trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2010-01-24 17:41:59 UTC (rev 4924)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using Iesi.Collections.Generic;
using log4net;
using NHibernate.Engine;
@@ -229,6 +230,18 @@
else
{
log.Info("lazy property fetching available for: " + name);
+ foreach (var prop in persistentClass.PropertyClosureIterator)
+ {
+ if (prop.IsLazy == false)
+ continue;
+
+ var getter = prop.GetGetter(persistentClass.MappedClass);
+ if(getter.Method == null ||
+ getter.Method.IsDefined(typeof(CompilerGeneratedAttribute), false) == false)
+ {
+ log.ErrorFormat("Lazy property {0}.{1} is not an auto property, which may result in uninitialized property access", persistentClass.EntityName, prop.Name);
+ }
+ }
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2010-01-24 16:46:51 UTC (rev 4923)
+++ trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2010-01-24 17:41:59 UTC (rev 4924)
@@ -1,6 +1,8 @@
using System.Collections;
+using log4net.Core;
using NHibernate.ByteCode.Castle;
using NHibernate.Cfg;
+using NHibernate.Tuple.Entity;
using NUnit.Framework;
namespace NHibernate.Test.LazyProperty
@@ -8,6 +10,8 @@
[TestFixture]
public class LazyPropertyFixture : TestCase
{
+ private string log;
+
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
@@ -24,6 +28,15 @@
typeof(ProxyFactoryFactory).AssemblyQualifiedName);
}
+ protected override void BuildSessionFactory()
+ {
+ using (var logSpy = new LogSpy(typeof(EntityMetamodel)))
+ {
+ base.BuildSessionFactory();
+ log = logSpy.GetWholeLog();
+ }
+ }
+
protected override void OnSetUp()
{
using (var s = OpenSession())
@@ -70,6 +83,12 @@
}
[Test]
+ public void ShouldGenerateErrorForNonAutoPropLazyProp()
+ {
+ Assert.IsTrue(log.Contains("Lazy property NHibernate.Test.LazyProperty.Book.ALotOfText is not an auto property, which may result in uninitialized property access"));
+ }
+
+ [Test]
public void PropertyLoadedNotInitializedWhenUsingGet()
{
using (ISession s = OpenSession())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|