0
votes

I am trying to perform a query using Breeze that will return a filtered selection of child entities. I have two custom dtos defined as follows:

#region Dto Models
public class ProductDto   {

    public int ProductDtoId { get; set; }

    public int ProductClassId { get; set; }

    public ICollection<ProductRequiredInputDto> RequiredInputs { get; set; }   
}


public class ProductRequiredInputDto
{

    public int ProductRequiredInputDtoId { get; set; }

    public string Product { get; set; }

    public string Capacity { get; set; }

    public string Electrical { get; set; }

    //Navigation properties
    public virtual ProductDto ProductDto { get; set; }

}
#endregion

My first query is to simply return a populated ProductDto model.

var query1a = this.entityQuery.from('ProductModel')
    return this.entityManager.executeQuery(query1a) // returns a promise
                    .then(data => { this.product = data.results} 

When I make a call to my web api controller everything works as expected as I receive a singular ProductDto model populated with a collection of ProductRequiredInputDto models. Here is a sample:

0: ProductDto__IPE_Data_DtoModels ProductClassId: 1 ProductDtoId: 1 RequiredInputs: Array[40] _backingStore: Object ProductClassId: 1 ProductDtoId: 1 RequiredInputs: Array[40]

Now, what I am trying to achieve is to perform a second query on the ProductDto model that will return a filtered array of ProductRequiredDto models from the RequiredInputs property. I have looked over the Breeze examples and samples but have not been able to find a solution to this particular question.

2

2 Answers

0
votes

Short answer: No I don't think you can filter on ICollection Navigation Properties from the EntityQuery.

Longer answer: You can write a custom method on the controller that uses .Include("RequiredInputs") and you can use LINQ to perform the filtering you want on the controller.

Aside: I find it peculiar that you don't have a ProductDtoID property on the ProductRequiredInputDto object.

0
votes

Is it absolutely necessary to call the function that retrieves ProductDto? Because it doesn't sound logical to me. I would create a controller function:

    [HttpGet]
    public IQueryable<ProductRequiredInputDto> ProductRequiredInputDtos()
    {
        return _contextProvider.ProductRequiredInputDto;
    }

And use a client side query in the lines of:

var idPredicate =  breeze.Predicate.create('id', '==', yourSelectedProductDtoId);
var yourPredicate = breeze.Predicate.create('yourProductRequiredInputDtosProperty, 'yourOperator, 'yourValue');
var query = entityQuery.from('ProductRequiredInputDtos').where(idPredicate).and(yourPredicate);

Jonathan's method would also work, but then you have a specialized controller function for one type of call and those pile up quickly (unless you make them general by receiving params but that's another story). This way you can do any query on this model from your client without cluttering the controller up.