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 implement the TestAsync method, where I want to work with the Topic object and related Posts objects.
Theme Model I can use the async method and topicId as a parameter.
public async Task<bool> TestAsync(int topicId) { var topic = await topicService.GetByIdAsync(topicId);
And I have two ways how to get related messages. But what is the difference if I use LazyLoading or just another asynchronous request?
// Example: 1 (LazyLoading) var posts = topic.Posts; // OR Example: 2 (Async method) var posts = await postService.GetAllByTopicIdAsync(topicId);
So, I think an example: 1 will work synchronously, and also I will lose all the benefits of async / wait code. But an example: 2 makes me think, maybe I don’t know all the charms of Lazy Loading :) Can someone clarify which solution I should use and why? Thanks:)
source share