views:

106

answers:

2

If a project has used POCO for entities and uses entity framework and uses lazy loading then you have an "incomplete" object graph going back over the wire. So when a client uses the Entity is there some sort of proxy that will automagically load the remaining values? Do we have to create this proxy ourselves and wrap the original entity in it? Or is there an accepted pattern for identifying lazy loaded types which would then signal the client to make another call to the WCF?

+1  A: 

Use flat DTO's, you probably don't want to expose your full domain to the client anyway. WCF is message-based, not Domain Driven.

IceHeat
+1  A: 

Lazy loading with WCF usually doesn't work because your method looks like:

public List<MyPoco> GetData()
{
  using (var context = new MyObjectContext())
  {
    return context.MyPocos.ToList();
  }
}

As you see context is closed in method (you have to close context somewhere). But when the list is serialized it will try to lazy load dependent objects => exception because context is already closed. In WCF you should use eager loading.

Ladislav Mrnka
...and even if the context wasn't closed, it would *still* be a bad idea. Lazy loading is too chatty for distributed objects.
Craig Stuntz
The problem that we have is that we have some accounts with many thousands of line items. We don't want to serialize that across the wire unless someone has asked for it.
uriDium
So you need two operations. One with items and one without items
Ladislav Mrnka
@uriDium You can eager load with a filter expression on the EF to restrict the record count. Then implement some form of paging functionality on the service for additional record requests if the client requires this.
Daz Lewis