Created
October 2, 2012 22:48
-
-
Save hlodwig/3823807 to your computer and use it in GitHub Desktop.
Enhancing performance in GetTable<T>() - Linq to Sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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