I have two methods:
Public Function GetTotalLimit(ByVal entity As Entity) As Int64
Return (From c In entity.Collection
Select c.Limit).Sum()
End Function
Public Function GetTotalUsed(ByVal entity As Entity) As Int64
Return (From c In entity.Collection
Select c.Used).Sum()
End Function
I have a feeling that these can be refactored to one single method with the signature:
Public Function GetTotal(Of TKey)(ByVal entity As Entity, ByVal field As Func(Of CollectionType, TKey)) As Int64
End Function
I come from a C# background which is hindering me to figure out the meat of this method. Anyone can help?
Why not use IQueryable on your “Get” Statement,
and do your queries on those Functions.
Have a look at My Blog where I talk about Separating Concerns in your Data Access.
EDIT:
Since your methods are
GetTotalLimitandGetTotalUsed, I’m not sure what “objects” you’re getting. I’ll try and wing it using my user class.Keep the IQueryable the same, and in your call to the method you would do something like