从asp.net vb.net中的dal函数返回多个ilist
我修改了一个函数,该函数从存储过程返回强类型的产品列表(来自网络搜索表单)。
由于存储过程的复杂性,我已将其更改为返回产品类别以及使用产品结果。我可以将其放入另一个强类型 ilist 中,但我无法返回这两个 ilist。
不幸的是,在阅读了数百篇文章后,我耗尽了天赋,似乎用 linq 是可能的,但我宁愿不走那条路,因为我在那里的知识更少。
是否可以将 ilists 放入某种集合中并将它们返回以用作 ilists?
如果没有还有其他办法吗?我可以再次调用存储过程,但调用两次成本高昂。
'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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否考虑过简单地返回一个仅包含
IList
和IList
的更粗略的对象?如果您绝对必须返回两个列表,那么这很容易实现。
Have you considered simply returning a more coarse object that simply contains both an
IList<Product>
and anIList<Category>
?If you absolutely must have both lists returned, than this is pretty easy to implement.
具有两个列表作为属性的自定义对象?
A custom object with the two lists as properties?
也许是匿名类型?
但必须承认 - 这不是我在 VB 方面非常有经验的领域...
Martin。
Perhaps an Anonymous Type?
Must admit though - this isn't an area I'm very experienced in with VB...
Martin.
一个函数可能只有一个返回值;然而,正如 Josh 和 Sergio 所建议的那样,返回值可以是某种包含多种事物的对象或结构。另一种方法是使用
ref
或out
参数通过函数参数返回值。例如,您可以指定函数的两个参数是对列表的引用,函数将在其中存储它找到的产品和类别;函数完成后,您可以检查这些列表中的数据。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
orout
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.为了完整起见,我想补充一点,您可以使用
ByRef
参数“返回”值:就个人而言,我更喜欢“自定义对象”变体。
For completeness, I would like to add that you can "return" values using a
ByRef
parameter:Personally, I'd prefer the "custom object" variant.