Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to handle an array of arrays in MediatR

I have a command

public class UpdateEntityCommand: IRequest<bool>
{
    public int Id { get; set; }
    public IEnumerable<OtherEntityDto> Instruments{ get; set; }
}

I need to update many entities in one request. Can I do something like this or there are a better way?

public class UpdateEntitiesCommand: IRequest<bool>
{
    public IEnumerable<UpdateEntityCommand> Commands { get; set; }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Supposing your OtherEntityDto is something like this:

class OtherEntityDto 
{
   public Guid Id {get;set;}
   public string Name {get;set;}
}

How I would do it is to have a command such as:

public class UpdateInstrumentsCommand: IRequest<bool>
{
   public IEnumerable<OtherEntityDto> UpdatedInstrumemnts {get;set}
}

and then, in the command handler I will match the persisted entities with what’s in the UpdatedInstrumemnts based on the Id property and update their name accordingly. I hope this makes sense to you

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading