Why this EntityManagerSaveException?

I am using Silverlight 4 and DevForce 6.1.11.0

I have some POCO classes that implement EntityAspect.

When changes are saved via EntityManager.SaveChanges; DevForce does not save these POCO entities to the server, because these POCO entities are not part of EF.

Instead I send them to a webservice via WebClient.UploadStringAsync.

This works, expect when I am saving more than one entity of the same type. Then I get this exception:

EntityManagerSaveException: An entity with this key: PocoMyClass: 0,0 already exists in this entityManager

I have checked the cache, and there is no entity with that key.

The WebClient.UploadStringAsync still sends the data and everything gets saved, but the exception does not look good to customers.

How do I work around this exception?

Upvotes: 0

Views: 104

Answers (1)

The poco entities that I am having problems with are only supposed to live on the client, not the DevForce server. The reason is that only the client can access these on the local network.

So I am using WebClient.OpenReadAsync to read the data in and create the poco entities on the client. And then I use WebClient.UploadStringAsync when saving the poco entities.

When creating the poco entity and adding it to the entitymanager, I do like this:

var pocoEntity = new PocoMyClass();
pocoEntity.keyId = some integer;
…
entityManager.AddEntity(pocoEntity);
pocoEntity.EntityAspect.AcceptChanges();

After doing this I see that the properties for EntityVersion.Original of the poco entity only contains empty stuff (NULL´s and zero’s).

Is this the reason for the exception when saving?

How can I manipulate EntityVersion.Original when the entity does not come from the DevForce server?

Upvotes: 0

Related Questions