Problem with lazy loading implementation
Posted
by
Mehran
on Stack Overflow
See other posts from Stack Overflow
or by Mehran
Published on 2010-12-23T16:50:45Z
Indexed on
2010/12/23
16:54 UTC
Read the original article
Hit count: 308
Hi,
I have implemented lazy loading in my program. it's done through a proxy class like:
class Order
{
public virtual IList<Item> Items {get; set;}
}
class OrderProxy
{
public override IList<Item> Items
{
get
{
if (base.Items == null)
Items = GetItems(base.OrderID);
return base.Items;
}
set { base.Items = value; }
}
}
the problem is that whenever i instantiate proxy class,without even touching the Items property, it tries to load Items! as you may know,i want to instantiate proxy class and return the instance to BLL instead of domain object itself.
what's the problem? Does .NET CLR access(read) properties in a class, when it's instatiating the class? any other methods?
Thanks
© Stack Overflow or respective owner