Skip to content

Instantly share code, notes, and snippets.

@marcusoftnet
Created August 14, 2012 13:49
Show Gist options
  • Select an option

  • Save marcusoftnet/3349404 to your computer and use it in GitHub Desktop.

Select an option

Save marcusoftnet/3349404 to your computer and use it in GitHub Desktop.
WithClause constraing to Top 1
// Given this simple class
public class Kid
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Quote> Quotes { get; set; }
}
// Now I have to write this long-winding code
private Kid GetKidWithQoutes(int kidId)
{
Kid kid = DB.Kids.FindById(kidId);
IEnumerable<Quote> quotes = DB.Quotes.FindAllByKidId(kidId).Cast<Quote>();
kid.Quotes = quotes.ToList();
return kid;
}
// I want this way of doing things.
// But using this code renders a TOP 1 making the Quotes-list on Kid
// containing just one member
private static Kid GetKidWithQoutes(int kidId)
{
return DB.Kids.WithQuotes().FindById(kidId);
}
@ThatRendle

Copy link
Copy Markdown

Yeah, that's a tiny little lump of stupid I accidentally added to the SQL Server provider. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment