0

I'm working with Breeze and love it but came across a stickler or two and am hoping to get a little help with one of them.

I'm using EF and SQL on the back-end of a database first model and have a one to many relationship with a Parent and Child table. When retrieving data, no matter what I try, it doesn't filter the data correctly when using the child id. Here's the code:

Client Code:

    var query = breeze.EntityQuery.from("Parent")
    var predicateChild = new breeze.Predicate('CHILD', 'any', 'CHILD_ID', '==', childId);

    query = query.where(predicateChild );
    var promise = collectionsManager
                .executeQuery(query)
                .then(querySuccess)
                .catch(queryFailed);

Server Code:

    [HttpGet]
    [BreezeQueryable(MaxExpansionDepth = 5)]
    public IQueryable<PARENT> Parent()
    {
        return _contextProvider.Context.PARENT;
    }

The query does work, it finds the proper parent (so it seems the childId is being used) but returns all children, not just the one given in the predicate.

I've tried every way I can to get the results I want but I'm sure I'm missing something either in the server code or the EF layer.

In an effort to get this to work, I changed the server code to use the child table instead of the parent. If navigation is set in EF from child to parent, this works, but that presents a circular reference when stringifying the data later downstream (and I need to do this).

Any help is greatly appreciated.

chuckm
  • 1
  • 2

1 Answers1

0

Your query has a filter on PARENT. It does not filter related CHILD entities, which seems to be the intent of your question.

Specifically you're query filters for a PARENT which has at least one CHILD whose CHILD_ID == childId. It does not return any CHILD entities as written. If you added an expand clause you would get all of the PARENT entity's children, not just the one with CHILD_ID == childId.

EF and OData do not support filtering of entities returned via an expand. Sorry about that. I wish they did.

This question comes up a lot. It's discussed in many S.O. answers, most recently this one.

Community
  • 1
  • 1
Ward
  • 17,793
  • 4
  • 37
  • 53