Skip to content

What does deleting instances look like? #118

Answered by rofr
TheColonel2688 asked this question in Q&A
Discussion options

You must be logged in to vote

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{T…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@TheColonel2688
Comment options

@rofr
Comment options

rofr Feb 4, 2021
Maintainer

@TheColonel2688
Comment options

Answer selected by TheColonel2688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants