tags:

views:

57

answers:

1

I have an oData generated DataServiceContext and I am successfully adding entities to it. I need to add a whole load of entities and then commit them in a single SaveChanges with the Batch option set at the end. This is all fine, until I come to query it before the save changes.

Outline is:

  • Create a new entity
  • Add it to the DataServiceContext
  • Run a query on the context looking for the item I have just added - IT IS NOT FOUND

My previous work with EF4 would suggest that if this was an Entity Context, all would be fine, but because this is a Service Context I cannot query for an entity that has been added but not saved to the service.

Is this the case?

+2  A: 

DataServiceContext is basically just a small helper. Running any query against it will run the query on the server directly, the client will not try to fixup the data in any way. Since you're changes haven't made it to the server yet (SaveChanges was not called yet), the query will not return the newly added entities. If you really need to list the entities you've added before SaveChanges, you could use the DataServiceContext.Entities collection which will return EntityDescriptor for all entities tracked by the context. You can list those added by looking for those with state Added.

Vitek Karas MSFT