Hi All,
I am facing a scenario where I am trying to return a list of "ProductTypes". I may need this list in many places in the code and so defined an async method and then calling that method from another async [HttpGet] method and trying to retrun the resut to the frontend.
I can understand we cannot convert an Interface to another Interface, but since am returning a list of ProductTypes, so it shouldn't have been any problem.
The async method is shown below:
<pre><pre>private async Task<IEnumerable<ProductTypesData>> GetProductTypes() {
return await _context.ProductTypePool
.Where(ProdType => ProdType.ProdParentTypeId == 0 && ProdType.IsActive == true)
.OrderBy(ProdType => ProdType.ProdTypeId)
.Select(ProdType => new ProductTypesData { ProdTypeId = ProdType.ProdTypeId, ProdTypeName = ProdType.ProdTypeName, ProdTypeDesc = ProdType.ProdTypeDesc})
.ToListAsync();
}
Then, am calling this method from annother async [HttpGet] method, as shown below:
[HttpGet]
public async Task<ActionResult<IEnumerable<ProductTypesData>>> GetAllProductTypes()
{
return this.GetProductTypes();
}
What I have tried:
I tried to wrapthe result into a concrete List class:
[HttpGet]
public async Task<ActionResult<IEnumerable<ProductTypesData>>> GetAllProductTypes()
{
return new List<ProductTypesData>(this.GetProductTypes());
}
But, this didn't work out.
I also tried to Use IList instead of IEnumerable but things are same there also.
Please help me knowing the way out in such conditions where I may have to return a list of data and that list may be used in many places in the code.
Thanks.