Created
August 14, 2012 13:49
-
-
Save marcusoftnet/3349404 to your computer and use it in GitHub Desktop.
WithClause constraing to Top 1
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
| // 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); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, that's a tiny little lump of stupid I accidentally added to the SQL Server provider. Will fix.