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?
views:
106answers:
2
+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
2010-09-22 10:11:05
+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
2010-09-22 12:18:59
...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
2010-09-22 12:49:57
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
2010-09-22 13:20:51
So you need two operations. One with items and one without items
Ladislav Mrnka
2010-09-22 13:25:38
@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
2010-09-22 13:32:38