JRockFL
asked on
Pass collection base class between tiers
I have two classes that inherit from CollectionBase
One is in the dataaccess class library and the other is in the business library.
I get this complier error when I try to return the object through the tiers.
value of type orm.dataaccess.usercollect ion can not be converted to orm.business.usercollectio n
Public Shared Function GetAll() As ORM.Business.UserCollectio n
Dim uc As New ORM.DataAccess.UserCollect ion
uc.Load()
Return uc
End Function
Why can't I do this? What should I do?
One is in the dataaccess class library and the other is in the business library.
I get this complier error when I try to return the object through the tiers.
value of type orm.dataaccess.usercollect
Public Shared Function GetAll() As ORM.Business.UserCollectio
Dim uc As New ORM.DataAccess.UserCollect
uc.Load()
Return uc
End Function
Why can't I do this? What should I do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Exactly, AW's description hopefully makes the point alot clearer for you, JRockFL.
ASKER
Thanks for the replies. Yes that does make sense AW.
After thinking about, I don't think I would need to pass the collectionbase class between the tiers. Would it make more sense to pass a datareader?
What I am trying to do is move my current architecture to a 3 tier.
Here is a sample of code that executes a reader and then adds the user objects to the class that inherits from collectionbase.
After thinking about, I don't think I would need to pass the collectionbase class between the tiers. Would it make more sense to pass a datareader?
What I am trying to do is move my current architecture to a 3 tier.
Here is a sample of code that executes a reader and then adds the user objects to the class that inherits from collectionbase.
Try
reader = _dp.ExecuteReader("Users_Collection", hsh)
If Not reader Is Nothing And Not reader.IsClosed Then
While reader.Read()
Dim objUser As New User
If Not reader.IsDBNull(0) Then
objUser.UserID = reader.GetInt32(0)
End If
If Not reader.IsDBNull(1) Then
objUser.UserName = reader.GetString(1)
End If
If Not reader.IsDBNull(2) Then
objUser.Password = reader.GetString(2)
End If
List.Add(objUser)
objUser = Nothing
End While
reader.Close()
End If
Catch ex As Exception
Throw ex
End Try
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help!
Glad to be of assistance.
AW
AW
Diddo. :)
You are dimensioning uc as ORM.DataAccess.UserCollect
You can either pass back the former OR CollectionBase (whatever class you extended).
When you add reference one layer from the other, you can use class from within the other if that is what is being returned to NOT have two classes OR only pass back and forth the public interface like CollectionBase and only use the other classes for implementation specific properties/methods within each layer.