Skip to content

Instantly share code, notes, and snippets.

@alexyork
Created September 2, 2010 12:55
Show Gist options
  • Save alexyork/562245 to your computer and use it in GitHub Desktop.
Save alexyork/562245 to your computer and use it in GitHub Desktop.
// 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