Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Comment
- {
- public string Message {get; set;}
- public DateTime Created {get; set;}
- }
- public class Post
- {
- public int PostId {get; set;}
- public string Content {get; set;}
- public IList<Comment> Comments {get; set;}
- }
- var query = from p in _repository.GetPosts()
- where p.PostId == id
- orderby p.Comments.Select(x => x.Created)
- select p;
- return query.Single();
- orderby p.Comments.Max(x=>x.Created)
- Post post = ...
- post.Comments = post.Comments.OrderBy(x=>x.Created).ToList();
- post.Comments.Sort((x, y) => (x.Created.CompareTo(y.Created)));
- post.Comments.Sort(x=>x.Created);
- public static void Sort<TSource, TKey>(
- this List<TSource> source,
- Func<TSource, TKey> selector)
- {
- var comparer = Comparer<TKey>.Default;
- source.Sort((x, y) => comparer.Compare(selector(x), selector(y)));
- }
- p.Comments.Select(x => x.Created)
- p.Comments.Max(x => x.Created)
- var query = from p in _repository.GetPosts()
- where p.PostId == id
- orderby {
- Comment comment = p.Comments.FirstOrDefault();
- return comment == null ? DateTime.MinValue : comment.Created;
- }
- select p;
- p.Comments = p.Comments.OrderBy(x => x.Created).ToList();
- var query = from p in _repository.GetPosts()
- where p.PostId == id
- orderby p.Comments.Select(x => x.Created)
- select p;
- var ret = query.Single();
- ret.Comments = ret.Comments.OrderBy(x => x.Created).ToList();
- return ret;
Add Comment
Please, Sign In to add comment