Skip to content

Instantly share code, notes, and snippets.

@hlodwig
Created October 2, 2012 22:48
Show Gist options
  • Save hlodwig/3823807 to your computer and use it in GitHub Desktop.
Save hlodwig/3823807 to your computer and use it in GitHub Desktop.
Enhancing performance in GetTable<T>() - Linq to Sql
void Main()
{
//This method will be too slow to work with
ObtainDataWrong<MyEntity>(k => k.MyProperty == value);
//Excellent performance
ObtainDataRight<MyEntity>(k => k.MyProperty == value);
}
private void ObtainDataWrong<T>(Func<T, bool> selector) where T : class
{
GetTable<T>().Where(selector).Dump();
}
private void ObtainDataRight<T>(Expression<Func<T, bool>> selector) where T : class
{
GetTable<T>().Where(selector).Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment