Reputation: 1329
When I have a controller method like this:
public IQueryable<ClassBase> Get()
{
}
and I return an IQueryable of ClassBase derived classes, the serializer serializes the derived class and the derived class is transferred (I tested just JSON) This is not what I want/expect.
Is there a way to just get the output of the base class?
Upvotes: 1
Views: 585
Reputation: 353
The serializer is going to serialize the object passed into it. You could tweak the derived class to provide instructions on how it should be serialized, but you probably don't want to do that.
This is why the MVVM design pattern exists- what you really should do is project your business object into a View Model object that has just the fields you actually want. Something like this:
public IQueryable<ClassViewModel> Get()
{
return CollectionOfClassDerivedObjects.Select(x => new ClassViewModel(x))
}
Upvotes: 2