Now, let us understand the build and fetch pattern using which we execute all our queries.
The query gets executed in the process or end point where pre-bus runs.
So before that, let us have a look at our controller action GetCustomerById.
public partial class CustomerController : FlexControllerBridge
{
[HttpGet()]
[Route("GetCustomerById/{id}")]
public GetCustomerByIdOutputAPIModel GetCustomerById(string id)
{
GetCustomerByIdParams parameters = new GetCustomerByIdParams();
FlexHostContextInfoBridge hostContextInfo = new FlexHostContextInfoBridge();
hostContextInfo.Populate<IFlexHostHttpContextAccesorBridge>(_appHttpContextAccessor);
parameters.SetHostContextInfo(hostContextInfo);
parameters.Id = id;
return ProcessCustomerService.GetCustomerById(parameters);
}
}
If you notice here, we have the GetCustomerById and passing the Id in an instance of GetCustomerbyIdParams.
Let's see what is the definition of this?
So it is located in our Query projects.
public class GetCustomerByIdParams : FlexiQueryParameterBridge
{
public string Id { get; set; }
}
It is HostContext is being accessed here and we are passing the parameter here.
So even if you need the tenant information or user information in the queries you have easily accessible there.
Now let us understand the query.
We will use the IFlexQueryRepositoryBridge and the IReadDbConnectionProviderBridge instead of the IWriteDbConnectionProviderBridge.
We are using a ProjectTo is a very handy auto-mapper method that maps the data and queries only those fields mentioned in the output model, which is a happy scenario for the DBA.
So, whatever you define in the output API model, it will fetch only those fields from the database. And a lot of time saved in writing long select statements even in LINQ.