File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
NHibernate.Test/NHSpecificTest/NH3132 Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -80,5 +80,30 @@ public void Query_returns_correct_name()
8080 Assert . AreEqual ( "First" , product . Name ) ;
8181 }
8282 }
83+
84+ [ Test ]
85+ public void Correct_value_gets_saved ( )
86+ {
87+ using ( var session = OpenSession ( ) )
88+ {
89+ Product product = session . CreateCriteria ( typeof ( Product ) )
90+ . Add ( Restrictions . Eq ( "Name" , "First" ) )
91+ . UniqueResult < Product > ( ) ;
92+
93+ Assert . IsNotNull ( product ) ;
94+ product . Name = "Changed" ;
95+
96+ session . Flush ( ) ;
97+
98+ session . Clear ( ) ;
99+
100+ Product product1 = session . CreateCriteria ( typeof ( Product ) )
101+ . Add ( Restrictions . Eq ( "Name" , "Changed" ) )
102+ . UniqueResult < Product > ( ) ;
103+
104+ Assert . IsNotNull ( product1 ) ;
105+ Assert . AreEqual ( "Changed" , product1 . Name ) ;
106+ }
107+ }
83108 }
84109}
Original file line number Diff line number Diff line change 33using System . Reflection ;
44using System . Reflection . Emit ;
55using NHibernate . Engine ;
6+ using NHibernate . Intercept ;
7+ using NHibernate . Proxy ;
8+ using NHibernate . Proxy . DynamicProxy ;
69using NHibernate . Util ;
710
811namespace NHibernate . Properties
@@ -154,6 +157,22 @@ private string GetFieldName(string propertyName)
154157 }
155158 }
156159
160+ private static object GetTarget ( object maybeProxy )
161+ {
162+ //wish there were an interface to unwrap with
163+ var proxy = maybeProxy as IProxy ;
164+ if ( proxy != null )
165+ {
166+ var fieldInterceptor = proxy . Interceptor as DefaultDynamicLazyFieldInterceptor ;
167+ if ( fieldInterceptor != null )
168+ {
169+ return fieldInterceptor . TargetInstance ;
170+ }
171+ }
172+
173+ return maybeProxy ;
174+ }
175+
157176 /// <summary>
158177 /// An <see cref="IGetter"/> that uses a Field instead of the Property <c>get</c>.
159178 /// </summary>
@@ -190,7 +209,7 @@ public object Get(object target)
190209 {
191210 try
192211 {
193- return field . GetValue ( target ) ;
212+ return field . GetValue ( GetTarget ( target ) ) ;
194213 }
195214 catch ( Exception e )
196215 {
@@ -275,7 +294,7 @@ public void Set(object target, object value)
275294 {
276295 try
277296 {
278- field . SetValue ( target , value ) ;
297+ field . SetValue ( GetTarget ( target ) , value ) ;
279298 }
280299 catch ( ArgumentException ae )
281300 {
You can’t perform that action at this time.
0 commit comments