BreezeJS / ODATA : Casts can only be performed on entity types
Asked Answered
A

1

6

Not sure if this is a Breeze or ODATA issue.

I'm having the following error upon execution of my ODATA query:

The child type 'job.volume' in a cast was not an entity type. Casts can only be performed on entity types.

The filter looks like this:

$filter:(JobGroup/JobJobGroup/any(x1: x1/job.volume eq 10d))

The where clause is built using the JSON notation:

{ "jobGroup.jobJobGroup": { "any": { "job.volume": { "eq": 10 } } } }

The model (only the relevant part):

public class WorkflowTask
{
    public virtual JobGroup JobGroup { get; set; }
}

public class JobGroup
{
    public virtual IList<JobJobGroup> JobJobGroup { get; set; }
}

public class JobJobGroup
{
    public virtual Job Job { get; set; }
    public virtual Guid JobId { get; set; }
    public virtual JobGroup JobGroup { get; set; }
    public virtual Guid JobGroupId { get; set; }
}

public abstract class Job
{
    public virtual Decimal Volume { get; set; }
}

public class JobEditing : Job
{

}

Could it be related to the Job class being abstract ?

Andromache answered 13/3, 2015 at 8:37 Comment(2)
of course it is. The error specifically says the child type wasn't an entity type, which means you don't have a DbSet for it, which makes sense, since it is abstract. How can you ask for data in a query that's being passed to the database from an object that doesn't exist in the database?Jinny
Of course I have the Job class mapped to a table in the database. It works fine in all scenarios but this one. I've edited my OP with another class inheriting from Job.Andromache
P
17

When using the JSON syntax with the any predicate you must use / instead of . for member access. This is the odata format

So the JSON becomes:

{ "JobGroup.JobJobGroup": { "any": { "Job/Volume": { "eq": 10 } } } }

Your odata query will then be:

$filter:(JobGroup/JobJobGroup/any(x1: x1/Job/Volume eq 10d))

Note: A secondary issue may be the casing of property names, they should exactly match the names in your model. eg. Cap V for job/Volume.

Phelia answered 18/6, 2015 at 1:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.