I have a method, that returns a group of accounts
Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??)
Using db As New MyEntity
Dim query= (From A In db.Account _
Where A.aspnet_Users.UserId = UserID _
Select A)
Return query
End Using
End Function
I would then like to pass this to another function to calculate the totals for all the accounts in the collection. Is it best practice to return an Ienumerable, a generic list, I'm just not sure what works best with LINQ and the entity framework.
By default, LINQ queries return a list of objects as an anonymous type. You can also specify that a query return a list of a specific type by using the Select clause.
A LINQ query can end with a GroupBy or Select clause. The result of GroupBy operators is a collection of groups. For example, GroupBy returns IEnumerable<IGrouping<TKey,Student>> from the Student collection: Return type of GroupBy()
The All method of System. LINQ. Queryable class returns a Boolean value if all the elements of the sequence satisfy the provided condition. It returns true if all the elements satisfy the condition otherwise it returns false.
Another option is to use LINQ's Select method. Normally, all we ask the Select method to do is return the object that will make up the new collection -- in fact, the Select method insists that the lambda expression passed to it return an object.
When propagating LINQ query results from methods in this manner, the best choice for the return type is IEnumerable(Of T)
for LINQ to objects or IQueryable(Of T)
for other LINQ providers. In this case it looks like Account
is the type so IEnumerable(Of Account)
or IQueryable(Of T)
depending on the query type in question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With