1: Public Class NullableTuplizer
2: Inherits PocoEntityTuplizer
3:
4: Sub New(ByVal entityMetamodel As EntityMetamodel, ByVal mappedEntity As PersistentClass)
5: MyBase.New(entityMetamodel, mappedEntity)
6: End Sub
7:
8: Public Overrides Function GetPropertyValuesToInsert(ByVal entity As Object, ByVal mergeMap As IDictionary,
9: ByVal session As NHibernate.Engine.ISessionImplementor) As Object()
10: Dim values() As Object = MyBase.GetPropertyValuesToInsert(entity, mergeMap, session)
11: ' Dirty hack 1
12: For i As Integer = 0 To values.Length - 1
13: If (values(i) Is Nothing AndAlso GetType(IEntity).IsAssignableFrom(getters(i).ReturnType)) Then
14: values(i) = ProxyFactory.GetProxy(0, Nothing)
15: End If
16: Next
17: Return values
18: End Function
19:
20: Public Overrides Function GetPropertyValues(ByVal entity As Object) As Object()
21: Dim values() As Object = MyBase.GetPropertyValues(entity)
22: ' Dirty hack 2
23: For i As Integer = 0 To values.Length - 1
24: If (values(i) Is Nothing AndAlso GetType(IEntity).IsAssignableFrom(getters(i).ReturnType)) Then
25: values(i) = ProxyFactory.GetProxy(0, Nothing)
26: End If
27: Next
28: Return values
29: End Function
30:
31: Public Overrides Sub SetPropertyValues(ByVal entity As Object, ByVal values() As Object)
32: ' Dirty hack 3
33: For i As Integer = 0 To values.Length - 1
34: If GetType(IEntity).IsAssignableFrom(getters(i).ReturnType) Then
35: Try
36: ' Provo ad accedere alla proprietà id
37: If CType(values(i), IEntity).ID = 0 Then
38: values(i) = Nothing
39: End If
40: Catch ex As Exception
41: ' Errore. Il proxy ha restituito un errore
42: values(i) = Nothing
43: End Try
44: End If
45: Next
46: MyBase.SetPropertyValues(entity, values)
47: End Sub
48:
49: End Class