Created
September 2, 2010 12:55
-
-
Save alexyork/562245 to your computer and use it in GitHub Desktop.
This file contains 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
// Example 1 | |
var query = from item _dataContext.PublishedItems | |
select item; | |
// When enumerated (i.e. looped) over, "query" will go to the DB, and get all items | |
// Example 2 | |
var query = from item _dataContext.PublishedItems | |
where item.ID > MyCustomMethod() | |
select item; | |
private int MyCustomMethod() | |
{ | |
return 42; | |
} | |
// When enumerated (i.e. looped) over, "query" will go to the database _MANY TIMES_, | |
// and call your method once for every row in the database, and return only those rows | |
// with ID > 42 | |
// NOT RECOMMENDED! | |
// Example 3 | |
int max = MyCustomMethod(); | |
var query = from item _dataContext.PublishedItems | |
where item.ID > max | |
select item; | |
private int MyCustomMethod() | |
{ | |
return 42; | |
} | |
// When enumerated (i.e. looped) over, "query" will go to the database _ONCE_ | |
// because it will construct a static SQL statement: | |
// SELECT * FROM PublishedItems WHERE ID > 42 | |
// RECOMMENDED! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment