public async IEnumerable<ParentClass> ReadResultAsync
{
var results = new List<ParentClass>();
results.Add(ChildClassA);
results.Add(ChildClassB);
return results;
}
I do this process in service layer.
When I return results => IEnumerable<ParentClass>
to Controller and show the results after calling a request, I face a problem:
It only returns the properties which the ParentClass has.
Ex.
ParentClass has property A, B, C.
ChildClassA inherit ParentClass has property D, E.
ChildClassB inherit ParentClass has property F.
The results only can get properties A, B, C. (Which I expect ChildClassA (A, B, C, D, E) and ChildClassB (A, B, C, F) in the same list)
My temporary solution is to change ParentClass to object, but I don't think it's good.
public async IEnumerable<object> ReadResultAsync
{
var results = new List<object>();
results.Add(ChildClassA);
results.Add(ChildClassB);
return results;
}
Is there any solution can create a parent list that can contain all child classes (which I want)?