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()
80
80
Assert . AreEqual ( "First" , product . Name ) ;
81
81
}
82
82
}
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
+ }
83
108
}
84
109
}
Original file line number Diff line number Diff line change 3
3
using System . Reflection ;
4
4
using System . Reflection . Emit ;
5
5
using NHibernate . Engine ;
6
+ using NHibernate . Intercept ;
7
+ using NHibernate . Proxy ;
8
+ using NHibernate . Proxy . DynamicProxy ;
6
9
using NHibernate . Util ;
7
10
8
11
namespace NHibernate . Properties
@@ -154,6 +157,22 @@ private string GetFieldName(string propertyName)
154
157
}
155
158
}
156
159
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
+
157
176
/// <summary>
158
177
/// An <see cref="IGetter"/> that uses a Field instead of the Property <c>get</c>.
159
178
/// </summary>
@@ -190,7 +209,7 @@ public object Get(object target)
190
209
{
191
210
try
192
211
{
193
- return field . GetValue ( target ) ;
212
+ return field . GetValue ( GetTarget ( target ) ) ;
194
213
}
195
214
catch ( Exception e )
196
215
{
@@ -275,7 +294,7 @@ public void Set(object target, object value)
275
294
{
276
295
try
277
296
{
278
- field . SetValue ( target , value ) ;
297
+ field . SetValue ( GetTarget ( target ) , value ) ;
279
298
}
280
299
catch ( ArgumentException ae )
281
300
{
You can’t perform that action at this time.
0 commit comments