I have an entity with a composite primary key that models a many to many relationship:
public class ActualAnswer
{
[Key]
[Column(Order = 0)]
public int AnsweredQuestionID { get; set; }
[Key]
[Column(Order = 1)]
public int AnswerID { get; set; }
}
If I delete one of these entities in my client application using Breeze, it's state is set to Deleted:
function deleteEntity(entity) {
var ea = entity.entityAspect;
ea.setDeleted();
}
If the user changes their mind I currently try to recreate the entity:
createEntity("ActualAnswer", {
AnsweredQuestionID: answeredquestionid,
AnswerID: answerid
});
which calls this function using my Breeze EntityManager:
function createEntity(entityType, initialValues) {
var entity = manager.createEntity(entityType, initialValues)
return entity;
}
However, that causes an error:
A MergeStrategy of 'Disallowed' does not allow you to attach an entity when an entity with the same key is already attached: ActualAnswer:#etc
It is true, we already have an entity with the same key - but it is in a "Deleted" state.
So, how can I retrieve that and undelete it?
Alternatively, can I safely use a different merge strategy? What are the pitfalls I need to look out for? Can I minimise the risk by using the merge strategy on this particular entity only?