Create Command then Read Query
See original GitHub issueHi,
Is it okay to call a create command and then the read to get the newly created record? (I have some loosely coupled objects which require some additional mapping to get the related entities)
public async Task<IActionResult> Post([FromBody] Create.Command command)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
var result = await _mediator.Send(command);
return Ok(_mediator.Send(new GetById.Query {Id = result.Id}));
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Should CQRS Command perform a Query?
My question is in the command handler, is it okay to perform queries to get the data to build the aggregate roots I...
Read more >How to run command-line SQLite query and exit?
Just include the command in quotes after the database file argument. For example, the following creates a table called abc :
Read more >c# - Select query to get data from SQL Server
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on...
Read more >CQRS pattern - Azure Architecture Center
CQRS stands for Command and Query Responsibility Segregation, a pattern that ... The read model uses the events to create a snapshot of...
Read more >A Using SQL Command Line
This section provides an introduction to SQL Command Line (SQL*Plus), an interactive and batch command-line query tool that is installed with Oracle Database ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess it have no problem since both calls are being made on your application entry point. What you should avoid is call Mediator.Send inside a Handler that responds to a previous Mediator.Send.
@TDK1964 “RESTful-ly” speaking, a Controller method that creates an entity should return the created entity’s Id. And also, the corresponding HTTP status response should be 201 Created. Why not changing the implementation of your
Create.Command
, to persist the entity and then return the corresponding Id, so you can avoid the “ugly” 2 calls to Mediator?