I have a situation where I have a self referencing hierarchy table with guids. In the ParentID there has to be nulls for it to be recognized as the top level parent. When I run this through my csla object, it crashes at populating the object such as LoadProperty(of Guid)(_ParentIDProperty,data.ParentID) with an error of NullReferenceException throw (I believe). Now I've tried to solve this with declaring my ParentID as a Nullable(of Guid) with no success. Does anyone else have a solution? This clsa build is 3.6
I am not so sure what your actual problem may be (your solution of making the ParentId nullable should work).
A couple of suggestions though:
ok in my BO I have this setup...
#region "Business Logic"
Private Shared _IDProperty As PropertyInfo(Of Guid) = RegisterProperty(Of Guid)(GetType(ProductCategory), New PropertyInfo(Of Guid)("ID", "ID", Guid.NewGuid))
Private _ID As Nullable(Of Guid) = _IDProperty.DefaultValue
Private Shared _ParentIDProperty As PropertyInfo(Of Guid) = RegisterProperty(Of Guid)(GetType(ProductCategory), New PropertyInfo(Of Guid)("ParentID", "ParentID", Guid.Empty))
Private _ParentID As Nullable(Of Guid) = _ParentIDProperty.DefaultValue
<System.ComponentModel.DataObjectField(True, True)> _
Public ReadOnly Property ID() As Guid
Get
Return GetProperty(Of Guid)(_IDProperty, _ID)
End Get
End Property
<System.ComponentModel.DataObjectField(True, True)> _
Public Property ParentID() As Nullable(Of Guid)
Get
Return GetProperty(Of Guid)(_ParentIDProperty)
End Get
Set(ByVal value As Nullable(Of Guid))
SetProperty(Of Guid)(_ParentIDProperty, value)
End Set
End Property
#End Region
#region "Child Data Logic"
Private Sub Child_Fetch(ByVal data As CK.Linq.ProductCategory)
LoadProperty(Of Guid)(_IDProperty, data.ID)
It crashes here when retrieving data from the DB if it has a null
LoadProperty(Of Guid)(_ParentIDProperty, data.ParentID)
LoadProperty(Of String)(_name, data.Name)
LoadProperty(Of String)(_description, data.Description)
LoadProperty(Of String)(_imageUrl, data.ImageUrl)
LoadProperty(Of ProductList)(_productlist, Productlist.GetProductList(data.XrefProductCategories.ToArray))
End Sub
#End Region
very odd... the only thing I can think of is your LoadProperty generic type is (of Guid) and might need to be (of nullable(of guid)):
LoadProperty(Of nullable(of Guid))(_ParentIDProperty, data.ParentID)
also, your register property static call should be:
Private Shared _ParentIDProperty As PropertyInfo(Of nullable(of Guid)) = RegisterProperty(Of nullable(Of Guid))(GetType(ProductCategory), New PropertyInfo(Of nullable(Of Guid))("ParentID", "ParentID", Guid.Empty))
I change to your solution because that was a great idea and also added.
Private Sub Child_Fetch(ByVal data As CK.Linq.ProductCategory)
LoadProperty(Of Guid)(_IDProperty, data.ID)
If data.ParentID.HasValue = True Then
LoadProperty(Of Nullable(Of Guid))(_ParentIDProperty, data.ParentID)
Else
LoadProperty(Of Nullable(Of Guid))(_ParentIDProperty, Guid.Empty)
End If
LoadProperty(Of String)(_name, data.Name)
LoadProperty(Of String)(_description, data.Description)
LoadProperty(Of String)(_imageUrl, data.ImageUrl)
LoadProperty(Of ProductList)(_productlist, Productlist.GetProductList(data.XrefProductCategories.ToArray))
End Sub
I feel as if I'm getting closer.. now I have no errors with no results... oh btw.. this is binding to a very plain treeview.
Copyright (c) Marimer LLC