I have these Domain Models
public class Topic
{
public int TopicId { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public int? TopicId { get; set; }
public virtual Topic Topic { get; set; }
}
For example I would like to impliment method TestAsync, there I want to work with Topic object and related Posts objects.
Topic model I can get using async method and topicId as param.
public async Task<bool> TestAsync(int topicId)
{
var topic = await topicService.GetByIdAsync(topicId);
// posts ...
}
And I have two ways, how to get related posts. But, what the difference if I will use LazyLoading or just another async query?
// Example: 1 (LazyLoading)
var posts = topic.Posts;
// OR Example: 2 (Async method)
var posts = await postService.GetAllByTopicIdAsync(topicId);
So, I think that Example:1 will works synchronously, and also that I lose all the advantages of async/await code. But Example: 2 makes me think, that may be I dont know all charms of Lazy Loading:) Could anyone clarify what solution I should use and why? Thanks:)