0

How can I apply an OData function on a related property of a breeze entity query?

For example, I have two entities EntityA and EntityB

public class EnityA{
   public ICollection<EntityB> Collection {get; set;}
}
public class EnityB{
   public DateTime DateColumn {get; set;}
   public EnityA One {get; set;}
}

I am able to create a breeze query on EntityB that uses OData functions. For example

var pred1 = Predicate.create('year(DateColumn)', '==', 2018)
var queryOnEntityB = EntityQuery.from('EntityB').where(pred1)

The query above works well. However, the query below DOES NOT work.

var pred1 = Predicate.create('year(DateColumn)', '==', 2018)
var pred2 = Predicate.create('Collection ', 'any', pred1)
var queryOnEntityA = EntityQuery.from('EntityA').where(pred2); 

I get the error

Cannot find a property named "DateColumn" on type "EntityA"

Strangely, it tries to find the column on the wrong entity. However, the following query works:

var pred1 = Predicate.create('DateColumn', '==', '2018-02-02')
var pred2 = Predicate.create('Collection ', 'any', pred1)
var queryOnEntityA = EntityQuery.from('EntityA').where(pred2); 

It therefore seems as the error only occurs when trying to include an OData function on the navigational property. Am I doing something wrong and how can this be corrected?

jpo
  • 3,959
  • 20
  • 59
  • 102
  • I am confused by your samples. They use `.where(pred)`, but have not defined `pred`, only `pred1` and `pred2`. If you use `EntityQuery.from('EntityB')`, then the query predicates should reference properties of EntityB. – Steve Schmitt Apr 02 '18 at 20:15
  • @SteveSchmitt sorry. That was a typo. it is corrected – jpo Apr 03 '18 at 16:53

0 Answers0