Reattaching an existing object to a DataContext

Jun 7, 2015 at 3:55 PM
Good Mornig.
We are using BrightStarDB to implement a new application.
The application at the moment uses an embedded configuration and brighstardb entity framework.
The application exposes via WebApi the Entities defined as Json object.
The application uses Unity for IoC and DI.
Now:
When a Rest API (PUT o POST ) is called a complete entity is passed from the client. An appropriate JsonConverter deserialize and rebuild the BrigstarDB entity and attaches it to the current context.
Which is the correct way to adopt in order to mark the object obtained as not new.
In our case there are corrects strategies to adopt ( to handle CRUD operation against BrigstarDB Entity Framework ) via Web Api and Json.
Don you need further information ?

Thanks in advance.
Coordinator
Jun 8, 2015 at 8:02 AM
Hi,

This sort of update scenario is something that we still need to provide some better support for in the EF (see https://github.com/BrightstarDB/BrightstarDB/issues/193). However, it is possible to achieve this with a bit of coding.

The main problem you will have will be with managing references to the modified entity. If you delete an entity, this deletes all incoming references to the entity. So, if you don't have any incoming references to the entity, then I would say just delete the entity and add the updated one as a new entity. If you do have incoming references then you probably need to have some code to retrieve the entity, modify its properties directly and then save it. Its a bit painful to do that right now as you end up having to write quite a bit of code - hopefully in the next release we will have something better sorted out for this.

Cheers

Kal
Jun 8, 2015 at 10:02 AM
Thank you for the replay.
(sorry for missing question marks)