views:

399

answers:

5

I modified a function that returns a strongly typed Ilist of products (from a web search form) from a stored procedure.

Because of the complexity of the stored procedure I have changed it to return productcategories as well using the product results. I can get this into another strongly typed ilist but for the life of me I cannot return the two ilists.

Unfotunatley I ran out of talent, after reading hundreds of posts, It seems it's possible with linq, but I would rather not go that way as I have even less knowledge there.

Is it possible put the ilists into a collection of some sort and return them for use as ilists?

If not is there any other way? I can call the stored procedure again but its way to expensive to call twice.

'Code Behind
Dim products As List(Of Product) = Dal.SearchProducts(st)

'Dal
Public Shared Function SearchProducts(ByVal searchstr As String) As List(Of Product)
Dim ProdList As List(Of Product) = New List(Of Product)()
Dim CatList As List(Of Category) = New List(Of Category)()

    ......
     Return Prodlist and Ilist please
A: 

A custom object with the two lists as properties?

Sergio
+2  A: 

Have you considered simply returning a more coarse object that simply contains both an IList<Product> and an IList<Category>?

public class ProductSearchDTO
{
    public IList<Product> {get; set;}
    public ILIst<Category> {get; set;}
}

If you absolutely must have both lists returned, than this is pretty easy to implement.

Josh
Nit: in this case, "coarse"
qid
Lol, yes I have made correction
Josh
A: 

Perhaps an Anonymous Type?

Must admit though - this isn't an area I'm very experienced in with VB...

Martin.

Martin
A: 

A function may only ever have one return value; however, as Josh and Sergio suggest, that return value can be some sort of an object or structure containing multiple things. An alternative is to return values via the parameters to the function, using either ref or out parameters. For example, you could specify that two of the parameters to the function are references to lists where the function will store products and categories it finds; once the function is finished, you can then examine those lists for data.

qid
A: 

For completeness, I would like to add that you can "return" values using a ByRef parameter:

'Code Behind
Dim products As List(Of Product)
Dim cats as List(Of Category)
Dal.SearchProducts(st, products, cats)

'Dal
Public Shared Sub SearchProducts(ByVal searchstr As String, _
                                 ByRef ProdList As List(Of Product), _
                                 ByRef CatList As List(Of Category))
    ProdList = New List(Of Product)()
    CatList = New List(Of Category)()

    ......
    ' No Return needed

Personally, I'd prefer the "custom object" variant.

Heinzi