我用我的FindOne
和FindAll
庫的重載調用來實現this..something,如:
Function FindOne(ByVal spec As ILinqSpecification(Of T)) As T
Function FindOne(ByVal spec As ILinqSpecification(Of T), ByVal strategy As IFetchingStrategy(Of T)) As T
Function FindAll(ByVal spec As ILinqSpecification(Of T)) As IQueryable(Of T)
Function FindAll(ByVal spec As ILinqSpecification(Of T), ByVal strategy As IFetchingStrategy(Of T)) As IQueryable(Of T)
等。
也許不是最乾淨的方法,但它完成這項工作。我不確定這是否仍然是主幹linq提供程序的問題,但我也可以根據我的提取策略是否包含一個或多個選項來決定是否將不同的結果轉換器應用於FindAll
方案中的結果採集。
我的規範和抓取策略實現基於ncommon項目中的可用規範。
僅供參考,我完全通用的「只讀」資料庫界面如下:
Public Interface IReadOnlyRepositoryWithTypedId(Of T As IEntityWithTypedId(Of IdT), IdT)
Function LoadById(ByVal id As IdT) As T
Function GetById(ByVal id As IdT) As T
Function FindOne(ByVal spec As ILinqSpecification(Of T)) As T
Function FindOne(ByVal spec As ILinqSpecification(Of T), ByVal strategy As IFetchingStrategy(Of T)) As T
Function GetCount() As Integer
Function GetCount(ByVal spec As ILinqSpecification(Of T)) As Integer
Function HasAny(ByVal spec As ILinqSpecification(Of T)) As Boolean
Function FindAll(ByVal spec As ILinqSpecification(Of T)) As IQueryable(Of T)
Function FindAll(ByVal spec As ILinqSpecification(Of T), ByVal strategy As IFetchingStrategy(Of T)) As IQueryable(Of T)
Function FindAll() As IQueryable(Of T)
Function FindAll(ByVal strategy As IFetchingStrategy(Of T)) As IQueryable(Of T)
End Interface
是否使用LinqSpecs?你可能會張貼這些方法的完整簽名嗎? – 2010-11-12 14:10:41
@Ben - 我相應地更新了我的答案,讓我知道你是否需要任何進一步的細節。 – DanP 2010-11-12 14:39:57
您可以考慮的另一種替代方法:http://fabiomaulo.blogspot.com/2010/07/enhanced-query-object.html我有興趣在未來的項目中嘗試這個概念。 – DanP 2010-11-12 15:13:10