ReadOnlyListBase Criteria

ReadOnlyListBase Criteria

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


SergioTorres posted on Sunday, August 05, 2007

I am using a ReadOnlyListBase (CSLA 2.1.1.) to fill a datagridview.

My table includes a column Delete_Flag (bit) and I want to be able to choose between retrieving only those rows that have Delete_Flag=False (or the number 0) or retrieving all rows. 

I added in my class code the criteria class like this:

<Serializable()> _
Private Class Criteria
   
Private mCondition As Boolean
   
Public ReadOnly Property Condition() As Boolean
      
Get
         
Return mCondition
      
End Get
   End Property
   
Public Sub New()
      mCondition = Back.booShowDeleteFlag
   
End Sub
End Class

I added a parameter in the class DataPortal_Fetch  to the sqlcommand like

cmd.Parameters.AddWithValue("@Delete_Flag", New Criteria())

And when I run my code I receive the following error message:

"DataPortal.Fetch failed (System.ArgumentException: No mapping exists from object type ...cContactList+Criteria to a known managed provider native type."

I'm lost here. What can I do to implement this "selective retrieve".

Marjon1 replied on Sunday, August 05, 2007

Sergio,

I would suggest taking a look at the ProjectTracker examples, provided with the framework.

However, the reason the your example fails is because the Criteria class can not be converted to a known SQL data type. Depending on the type of data_portal_fetch that you've used, you would need to the following:

Protected Overrides Sub DataPortal_Fetch(ByVal c As Object)

    --SqlConnection code
    cmd.Parameters.AddWithValue("@Delete_Flag" , DirectCast(c,
Criteria).Condition)

End Sub


You would normally pass the criteria object to the fetch method, therefore allowing you to determine if the delete_flag is shown within the factory method (doing the new crtieria there); instead of within the data_portal method itself. The other option is to overload the fetch method like the following:

Protected Overloads Sub DataPortal_Fetch(ByVal c As Criteria)

    --SqlConnection code
    cmd.Parameters.AddWithValue("@Delete_Flag" , c
.Condition)

End Sub

Copyright (c) Marimer LLC