What does deleting instances look like? #118
-
I've read over the quick start guide and the main read me, but I don't see anything about deleting instances. What does deleting instances look like? Can you provide an example? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi there! I'm assuming you mean deleting entities or objects from your in-memory model. So let's extend the quick start guide with a command to remove tasks: [Serializable]
public class RemoveTaskCommand : Command<TaskModel>
{
public readonly int TaskIndex {get;set;}
public override void Execute(TaskModel model)
{
model.Tasks.RemoveAt(TaskIndex);
}
} Removing based on the position in the list is not great design. A sounder approach would be to assign each task a unique id and remove by id instead. But hopefully this is enough to get you going. Using the command would look something like this: var engine = Engine.For<TaskModel>();
await engine.Execute(new RemoveTaskCommand{TaskIndex = 2}); Note that the quickstart referenced above is based on origodb, the predecessor of memstate. But with some minor tweaks should work with memstate as well. Let us know if you need more guidance. |
Beta Was this translation helpful? Give feedback.
Hi there! I'm assuming you mean deleting entities or objects from your in-memory model. So let's extend the quick start guide with a command to remove tasks:
Removing based on the position in the list is not great design. A sounder approach would be to assign each task a unique id and remove by id instead. But hopefully this is enough to get you going. Using the command would look something like this: