I have a class where some properties are going back to the database, ONLY when they are called. So, let consider the following example:
class User
{
public int UserID { get; internal set; }
public string UserName { get; set; }
public Role[] Roles
{
get
{
if (this.UserID > 0)
return RoleRepository.GetByUserID(this.UserID).ToEntityArray();
else
return RoleRepository.GetByUserName(this.UserName).ToEntityArray();
}
}
}
There is also a Role class, but that’s probably not important. The ‘Roles’ property in the ‘User’ class is kind of like lazy loading. It is only retrieving the info when that property is accessed. The question is how can I use JQuery to ensure that the lazy loading occurs or is that even possible? Any articles on this concept would also be helpful.
Thanks
I don’t see what jQuery has to do with this at all.
Touching that Property will trigger the lazy-load.
If you use JQuery to call some HttpHandler/WebMethod/ActionMethod/etc, as soon as you try to iterate through or access that Property it is going to load that data
Also, rather than having that biz logic in your domain object you could try a delegate approach to keep “how” data is bound to that Property in its proper place
Then you could bind that like so: