Showing posts with label linq. Show all posts
Showing posts with label linq. Show all posts

Tuesday, June 11, 2013

LINQ: Func<T> vs. Expression<Func<T>>

Continuing the previous post about differences between IEnumerable<T> and IQueryable<T> I would like to describe differences between Func<T> and Expression<Func<T>>, basic features of lambda expressions and expression trees and possible impact on Entity Framework.

What is Func<T>

Func<T> is just a predefined generic delegate which encapsulates a method that accepts no parameters and returns a value of type T. It's declared like:


public delegate T Func<out T>();


Its value can be assigned to a named method or to an anonymous method through delegate syntax or through lambda expression syntax. All the following assignments are correct and return the same result:

Saturday, April 13, 2013

Entity Framework: IQueryable vs. IEnumerable

Many of us sometimes get confused of different aspects of using IEnumerable<T> and IQueryable<T> in Entity Framework. One of considered opinions is that Entity Framework and DbContext and deffered execution just do all the magic and there is no difference. But even though LINQ query result remains basically the same, it may significantly impact the query performance.

Code sample

I'm going to create a simplified database consisting of one table with million records with Entity Framework Code First.