EF4: using Add Service Reference causes issues with STE(self tracking entities) not remember there changes?

StackOverflow https://stackoverflow.com/questions/4638699

Question

I found an issue but it refers to the BETA version of VS 2010. I am interested in knowing if this issue has been fixed in RTM?

Basically it states (saw it via EF 4 Self Tracking Entities does not work as expected )

Make certain to reuse the Self-Tracking Entity template’s generated entity code on your client. If you use proxy code generated by Add Service Reference in Visual Studio or some other tool, things look right for the most part, but you will discover that the entities don’t actually keep track of their changes on the client.

I am very used to using Add Service Reference, and its always worked great for me in the past but of course i wasn't using STE (Self tracking entities). Is this problem still apparrent with VS 2010 RTM and the STE template?

If i do create the proxy via code instead of add service then all the classes won't be created will they?

Any help or insight really appreciated

Was it helpful?

Solution

This is not an issue and it never was an issue. It is absolutly expected and correct behavior. STEs are classes which contains data and logic (the logic tracks changes).

When adding service reference your client proxy code is generated from service's metadata. Metadata are exposed in form WSDL. WSDL is XML based description of the service which also contains XSD description of transfered data types. XSD can describe only data format but not related logic implemented by the type. By default all unknown data types described in WSDL are generated on the client. So when you generate client proxy with all data types by Add service reference the tracking logic is lost.

To overcome this issue you have to do two things:

  • Create separate assembly and place all your STEs to this assembly. Then share this assembly among all involved layers (yes you have to use Add reference in your client).
  • Then you can use Add service reference with "Reuse types in referenced assemblies" checked.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top