I have these entities:
public class Post {
public virtual int Id { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
public class Tag {
public virtual int Id { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public class Comment {
public virtual int Id { get; set; }
public virtual Post Post { get; set; }
}
I want to load a Post
by it's related Tag
s and related Comment
s's count by LINQ
. I use this:
var posts = session
.Query<Post>()
.OrderBy(t => t.Id)
.Select(t => new {
Post = t,
CommentsCount = t.Comments.Count(),
Tags = t.Tags
}).ToList();
Do you think it is enough? or do you have any suggestion that may be better than my code? thanks.