How can performance change with greedy LINQ operators?

Is it possible to use greedy LINQ operators like ToList,ToLookUp,Distinct

etc.

What would be the best practice for doing LINQ queries? You often use for your objects List<>

or a list of all your objects in IEnumerable<>

. I know the latter gives a lot of flexibility.

When working with memory (LINQ to Objects) it is always convenient to use hyphenated loading, because you can access it when you need it without fear of data being modified, added or inserted, since the link will execute the query as soon as you will need access. But that changes with LINQ queries on the database like LINQ to EF.

You will love the feedback from StackOverflow users.

Thank!

+3


source to share


1 answer


What would be the best practice for doing LINQ queries?

The list can be accessed by index, the search can be accessed by a key. These types are obviously serializable across WCF border. Deferred IEnumerable doesn't do any good.

For EF or LinqToSql, you need to execute your queries before the DataContext or whatever contains the SqlConnection.




In my code, I only use deferred IEnumerables for scoped variables when convenient. I'm using List for properties (sometimes a property builds a List, but usually it's just maintained by the instance) and the return types of the method. Since I'm doing relatively expensive things (like database access or using WCF), the performance of looking forward to executing Linq queries in memory has never been an issue.

The ultimate authority on any performance question: how does it measure?

+1


source







All Articles