I'm building an OData service with Web API. Database access is handled via Entity Framework.
I am mapping my EF entities to another set of classes using AutoMapper. Those mapped classes are what is being exposed via the OData service.
I have a model that looks like this:
Assignment(int AssignmentId, int EmployeeId, Employee Employee)
Employee(int EmployeeId, ICollection<Skill> Skills)
Skill(int SkillId, string SkillName)
My OData endpoint exposes an IQueryable<Assignment>
. Everything works fine with simple OData queries ($top
, $select
, $filter
, etc). By default, Assignment.Employee
is not returned from the service; I am fine with that.
When I attempt to $expand
the Employee, I get this error:
{"error":{"code":"","message":"An error has occurred.","innererror":{"message":"Cannot compare 'member 'Skills' of type '[...].Employee''. Only primitive types, enumeration types and entity types are supported.","type":"System.NotSupportedException"[...]}
[...]
are not actually part of the error, just pieces of the message I've removed.
At this point I have not requested Skills
, and my expectation was that Employee.Skills
would not be expanded because I haven't explicitly requested to expand it. I am unsure what Skills
is being compared to that is throwing EF off.
The best I can tell is that OData is applying an additional projection on top of any projections I have applied, and it is that projection that EF is having issues with.
Has anyone had experience/success with using OData/EF to navigate properties that had more than one level of depth to it?
I have tried removing AutoMapper and writing the expressions by hand, but I still run into the same error, so I don't believe AutoMapper is causing any issues here.