Snapshot vs. Self-tracking via WCF in EF4 POCO

entity-framework poco self-tracking-entities snapshot wcf


Last year, I created a data access service for our project using Entity Framework (of course.NET3.5) and created state monitoring POCO objects using Julie Lerhman's book as a reference. We also have Silverlight 3 clients and utilize WCF. As we transition to.NET 4.0, I want to convert to code generation to cut down on the amount of time developers spend creating POCO classes and translation classes.

According to my study, there seem to be three approaches for states to monitor POCOs:

1) Modified tracked proxies: This doesn't seem to be of any value to us as it seems that WCF serialization prevents it from working.

2) Snapshot-based: When the POCO entity graph is obtained, a snapshot is taken, and the discrepancies between the provided client graph and the snapshot are compared. This approach sounds reasonable to me.

3) Self-Tracking Entities: The POCO objects' code generator produces logic for self tracking. Although it is all produced for us, it appears quite similar to what we do presently.

I'm attempting to determine the benefits and drawbacks of each of these approaches. Although I haven't been able to verify it, I suspect that 1 and 2 are "related" and that they need the ObjectContext that the POCOs were first queried from to stay instanciated. Additionally, because option 3 seems to do the same thing as option 1 and more, I fail to see why anybody would bother with it.

The easiest method appears to be a snapshot, however I'm not sure whether that is the case if an ObjectContext has to be open for a while.

I'm a novice coder, so any advise is much welcomed, particularly with reference to Silverlight 3 (I think alternatives 2 and 3 work with Silverlight 3, but 2 could have problems).

2/26/2010 12:38:20 AM

Accepted Answer

Self-Tracking Entities are the best choice for Option 3, since this is what they were made for.

"Self-tracking entities are designed for circumstances involving serialization"

these words provides an effective illustration.

2/26/2010 10:16:49 PM

Popular Answer

Only when modifications are made while the objectcontext is present are the other two choices available. STE is your only choice. Entities might monitor their own changes using STE. You may simply play those modifications when the server receives the changed object graph as seen below. db.Dustomers.ApplyChanges(customer);\sdb.SaveChnages();

You may develop your entities in a class library project using STE and share them with clients running WCF, Silverlight, Asp.Net, and WPF. As a result, you may reuse entities for different clients.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow