Having some issues getting proper results when creating a list of test events.
I am using CSLA 3.7.1
The issue is that the list that is returned to the program has the proper number of tests but all of the tests are the same.
In other words there seems to be an issue with the list using a reference to the same object for each of the EmployeeTest objects returned by GetChildItem.
Resulting in all of the items in the list being the last item returned.
The results of the Debug Print statement in the EmployeeTestsList show
>> Record Test_AN = 249371
>> Record Test_AN = 257789
>> Record Test_AN = 259444
>> Record Test_AN = 261276
>> Record Test_AN = 299916
>> Record Test_AN = 352359
>> Record Test_AN = 384673
>> Record Test_AN = 416849
>> Record Test_AN = 422689
>> Record Test_AN = 428135
>> Record Test_AN = 465173
>> Record Test_AN = 480984
>> Record Test_AN = 500611
But the list returned by GetList to the GUI shows all 13 tests being 500611
Any Ideas................................I have read in some other posts that with Windows forms I should be using BusinessBindingListBase. instead of BusinessListBase but I can not find that Class at all.
Here is the simplified setup
I have an EmployeeTestsList class that returns a list of EmployeeTest
<Serializable()> _
Public Class EmployeeTestsList
Inherits BusinessListBase(Of EmployeeTestsList, EmployeeTest)
Friend Shared Function GetList(ByVal employeeid As Integer) As EmployeeTestsList
Return DataPortal.FetchChild(Of EmployeeTestsList)(employeeid)
End Function
Private Sub Child_Fetch(ByVal employeeid As Integer)
Me.RaiseListChangedEvents = True
Dim data As New TestEvent
data.Where.Donor_AN.Value = employeeid
data.Query.Load()
If data.RowCount > 0 Then
Do
Debug.Print(" >> Record Test_AN = " & data.Test_AN.ToString) 'Added to be sure of return values
Add(EmployeeTest.GetChildItem(data))
Loop While data.MoveNext
End If
End Sub
End Class
The EmployeeTest Class
<Serializable()> _
Public Class EmployeeTest
Inherits BusinessBase(Of EmployeeTest)
Private Shared IdProperty As PropertyInfo(Of Integer) = RegisterProperty(Of Integer)(New PropertyInfo(Of Integer)("ID", "ID"))
Private Shared _idprop As Integer = IdProperty.DefaultValue
<System.ComponentModel.DataObjectField(True, True)> _
Public ReadOnly Property Id() As Integer
Get
Return _idprop
End Get
End Property
Private Shared EmployeeIDProperty As PropertyInfo(Of Integer) = RegisterProperty(Of Integer)(New PropertyInfo(Of Integer)("EmployeeID", "EmployeeID"))
Private Shared _empID As Integer = EmployeeIDProperty.DefaultValue
Public ReadOnly Property EmployeeID() As Integer
Get
Return _empID
End Get
End Property
Private Shared ReasonForTestingCodeProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(New PropertyInfo(Of String)("ReasonForTestingCode", "ReasonForTestingCode"))
Private Shared _reason As String = ReasonForTestingCodeProperty.DefaultValue
Public Property ReasonForTestingCode() As String
Get
Return _reason
End Get
Set(ByVal value As String)
SetProperty(Of String)(ReasonForTestingCodeProperty, _reason, value)
End Set
End Property
Private Shared EmployeeCatagoryCodeProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(New PropertyInfo(Of String)("EmployeeCatagoryCode", "Employee Catagory Code"))
Private Shared _empCatCode As String = EmployeeCatagoryCodeProperty.DefaultValue
Public Property EmployeeCatagoryCode() As String
Get
Return _empCatCode
End Get
Set(ByVal value As String)
SetProperty(Of String)(EmployeeCatagoryCodeProperty, _empCatCode, value)
End Set
End Property
Private Shared DateScheduledProperty As PropertyInfo(Of SmartDate) = RegisterProperty(Of SmartDate)(New PropertyInfo(Of SmartDate)("DateScheduled"))
Private Shared _dSched As SmartDate = DateScheduledProperty.DefaultValue
Public Property DateScheduled() As String
Get
Return _dSched.ToString("MM/dd/yyyy")
End Get
Set(ByVal value As String)
SetPropertyConvert(Of SmartDate, String)(DateScheduledProperty, _dSched, value)
End Set
End Property
Friend Shared Function GetChildItem(ByVal data As Data.TestEvent) As EmployeeTest
Return DataPortal.FetchChild(Of EmployeeTest)(data)
End Function
Private Sub Child_Fetch(ByVal data As Data.TestEvent)
With data
SetProperty(IdProperty, _idprop, .Test_AN)
SetProperty(EmployeeIDProperty, _empID, .EMP_ID)
SetProperty(ReasonForTestingCodeProperty, _reason, .TEST_TYPE)
SetProperty(EmployeeCatagoryCodeProperty, _empCatCode, .EMP_CAT)
SetPropertyConvert(Of SmartDate, String)(DateScheduledProperty, _dSched, .s_DATE_SCH)
End With
End Sub
End Class
BusinessBindingListBase doesn't exist until Csla 4, so no need to worry about that unti you upgrade. How are you displaying this in windows forms? Using the standard datagrid? Or some other control?
In the GUI The data is displayed in a Pure Components LightGrid control. However, It really does not matter since when debugging I can look at the returned object in the IDE and see that all of the returned list items are the same.
Put your Debug line in the Child_Fetch to make sure the parameter is the value you think it is.
The Child Fetch is getting the proper value. In fact the records shown in the data.Query are the expected values. Even when I check the values in EmployeeTestGetChildItem they are correct for each record in Data. I have also verified that the return from GetChildItem contains the expected result. But after the Loop Completes all values are the same.
What appears to be happening (and this is what I can not figure out) is that it appears that the Add is not creating a new object but referencing an the object in memory so when it is updated all instances are pointing to the same object.
I have even tried changing the add as follows with the same result.
Dim _FoundTest as EmployeeTest = EmployeeTestGetChildItem(data)
Add(_foundTest.Clone)
A bit more information on this issue..... It appears to be related to child items as any parent items are returning correctly.
I have also tried the following - Reinstalled .NET 3.5 SP1, Reinstalled VS2008 Professional, Reinstalled CSLA 3.7.1, and even tried changing to CSLA 3.6.3 All with the same resulting issue. I am at a loss as to what may be going on. I am beginning to think I am going to have to redesign my methods so that for listing information I can use the ReadOnlyListBase since I do not have this issue using it.....
I am looking for any clues as to something I may be overlooking or forgetting to do when it comes to child data...
Anyone......
Private Shared ReasonForTestingCodeProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(New PropertyInfo(Of String)("ReasonForTestingCode", "ReasonForTestingCode"))
Private Shared _reason As String = ReasonForTestingCodeProperty.DefaultValue
Public Property ReasonForTestingCode() As String
Get
Return _reason
End Get
Set(ByVal value As String)
SetProperty(Of String)(ReasonForTestingCodeProperty, _reason, value)
End Set
End Property
Found your problem:
Private Shared _reason As String = ReasonForTestingCodeProperty.DefaultValue
All your backing fields are shared.
Copyright (c) Marimer LLC