【发布时间】:2016-07-27 04:24:10
【问题描述】:
这个ObjectDataSource在连接到以下函数时会返回错误:
<asp:ObjectDataSource ID="odsActiveProductTypes" runat="server" SelectMethod="GetProductTypes" TypeName="MyRepo">
带可选参数的函数:
Public Function GetProductTypes(Optional ByVal activeOnly As Boolean = True) As IQueryable(Of ProductType)
If activeOnly Then
Return MyContext.ProductTypes.Where(Function(pt) pt.Active = True)
Else
Return MyContext.ProductTypes
End If
End Function
这是错误:
ObjectDataSource 'odsActiveProductTypes' 找不到非泛型 没有参数的方法“GetProductTypes”。
我意识到我可以通过向ObjectDataSource 添加参数来使代码工作,或者我可以重载函数,但这违背了可选参数的目的。
【问题讨论】:
标签: .net optional-parameters objectdatasource