3
votes

I have 2 POCO classes -- Contact and TrainingSeminar -- that joined in a many-to-many relationship using EF5

In the Contacts odata controller, I want to be able to return the TrainingSeminars that a contact is registered for...so I have the following controller method

public IQueryable<TrainingSeminar> GetTrainingSeminars([FromODataUri] int key)
{
    var contact = _context.Contacts.Find(key);
    var seminars = contact.TrainingSeminars.ToList();
    return seminars as IQueryable<TrainingSeminar>;
}

When I debug in Visual Studio, the return object "seminars" has 2 items but I get the following error in Fiddler:

"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json...."message":"Cannot serialize a null 'feed'

1

1 Answers

4
votes

From your code, seminars is a List<T> and hence the last line

return seminars as IQueryable<TrainingSeminar>;

would always be null as List<T> does not implement IQueryable<T>. You should be using,

return seminars.AsQueryable();

instead.