Lazy loading not making a call to the function
c#, lazy-loading
Solution
The point of the `Lazy` class is, according to the documentation to `Provides support for lazy initialization.`
So it's normal that
lazyList = new Lazy<List<userAudit>>(() => client.GetAudit(10).ToList());
doesn't call this method.
However, it will be called if you use the Value property
Problem
When I was debugging my application I found that the code line below is not making a call to any method in my service layer: ``` private Lazy<List<userAudit>> lazyList = null; lazyList = new Lazy<List<userAudit>>(() => client.GetAudit(10).ToList()); ``` And, my `GetAudit` method will return the list of Audit Object and below is its definition: ``` public List<t_user_audit> GetAudit(int id) { return _work.GetGenericRepositoryFor<List<userAudit>>().GetByID(id); } ``` And, in the above definition, I have inserted a break point, in the `GetAudit` method, but when the compiler is not coming to the break point and just returning me with the `NULL` values. I don't know where I have made a mistake or is what wrong with the code. I am following Can you explain Lazy Loading article.