Suggestion for a change to CslaDatasource

Suggestion for a change to CslaDatasource

Old forum URL: forums.lhotka.net/forums/t/1385.aspx


mtavares posted on Wednesday, October 04, 2006

Hi Rocky,

Yesterday, I posted an issue with passing an empty BO to a Detailsview so that the detailsview would know the BO is empty and act accordingly.  You can view that post here: 

http://forums.lhotka.net/forums/thread/7120.aspx

After some digging I think I have come up with a possible solution, in regards to changing some code in the ExecuteSelect method of the CslaDatasource.

 The original code had the following:

         ' if the result isn't IEnumerable then
          ' wrap it in a collection
            If Not TypeOf result Is IEnumerable Then
                Dim list As New ArrayList
                list.Add(result)
                result = list
            End If


Now with the original code if result (the BO) is nothing, then when the control is bound to the detailsview an error occurs.  But if I change it to:

         ' if the result isn't IEnumerable then
          ' wrap it in a collection
            If Not TypeOf result Is IEnumerable Then
                Dim list As New ArrayList
                If result IsNot Nothing Then
                    list.Add(result)
                End If

                result = list
            End If

Then I get the results I was looking for.  the Details view will return the Empty Data Row because it is looking at an empty ArrayList instead of an arraylist with one item set to nothing.  I decided to test this same thing out with a collection based BO with a gridview, and the results were still good where the Empty Data Row for the gridview was displayed.  I also tried a bound dropdownlist and it was still ok.

So that being said, do you see any repercussions with only adding the result to the list if it is not nothing?  My tests seemed to be fine, but I may not be accounting for something.

Thanks,
Mike

RockfordLhotka replied on Wednesday, October 04, 2006

That makes good sense, and I think you have hit on the correct answer here - thanks! I'll change this for the next version (probably 2.1.1).

Skafa replied on Wednesday, October 04, 2006

Cool hack. thank you, I'm bookmarking this...

Copyright (c) Marimer LLC