2
votes

I am getting the error:

Unable to locate member:

when filtering on an expanded entities property.

This works:

http://localhost:60760/XXX/XXX/productcollection?$filter=Code%20eq%20'da'&$expand=PRODUCT_LINE

And Returns:

[{"$id":"1","$type":"DoorDesigner.Models.COLLECTION, DoorDesigner","ID":81,"Descr":"Some Description","Code":"Da","DISPLAY_HTML":"","DEFAULT_IMAGE_PATH":"../Content/Images/TempCollections/0000_Layer 54.jpg","PRODUCT_LINE":[{"$id":"2","$type":"DoorDesigner.Models.PRODUCT_LINE, DoorDesigner","ID":213,"CollectionID":81,"Code":"AT","Descr":"ATHENA","LongDescr":"ATHENA","DEFAULT_IMAGE_PATH":"../Content/Images/TempCollections/0000_Layer%2054.jpg","Product_Code_Group":"AT","COLLECTION":{"$ref":"1"},"PRICING_DOOR":[],"POSSIBLE_INSULATION":[],"POSSIBLE_WINDOW":[],"WINDOWs":[]},{"$id":"3","$type":"DoorDesigner.Models.PRODUCT_LINE, DoorDesigner","ID":217,"CollectionID":81,"Code":"CY","Descr":"CYPRUS","LongDescr":"CYPRUS","DEFAULT_IMAGE_PATH":"../Content/Images/TempCollections/Panel.jpg","Product_Code_Group":"CY","COLLECTION":{"$ref":"1"},"PRICING_DOOR":[],"POSSIBLE_INSULATION":[],"POSSIBLE_WINDOW":[],"WINDOWs":[]},{"$id":"4","$type":"DoorDesigner.Models.PRODUCT_LINE, DoorDesigner","ID":220,"CollectionID":81,"Code":"PI","Descr":"PINNACLE","LongDescr":"PINNACLE","DEFAULT_IMAGE_PATH":"../Content/Images/TempCollections/Windows.jpg","Product_Code_Group":"PI","COLLECTION":{"$ref":"1"},"PRICING_DOOR":[],"POSSIBLE_INSULATION":[],"POSSIBLE_WINDOW":[],"WINDOWs":[]},{"$id":"5","$type":"DoorDesigner.Models.PRODUCT_LINE, DoorDesigner","ID":227,"CollectionID":81,"Code":"WI","Descr":"WINDRIVER","LongDescr":"WINDRIVER","DEFAULT_IMAGE_PATH":"../Content/Images/TempCollections/Panel.jpg","Product_Code_Group":"WI","COLLECTION":{"$ref":"1"},"PRICING_DOOR":[],"POSSIBLE_INSULATION":[],"POSSIBLE_WINDOW":[],"WINDOWs":[]}]}]

Notice, that PRODUCT_LINE is Expanded, and there is a Descr property.

Now, if I change the URL to filter on PRODUCT_LINE.Descr I get the error:

http://localhost:60760/XXX/XXX/productcollection?$filter=PRODUCT_LINE/Descr%20eq%20'Athena'&$expand=PRODUCT_LINE 

Returning:

{"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"Unable to locate member: Descr","ExceptionType":"System.Exception","StackTrace":"   at Breeze.WebApi.ParseTreeVisitor.VisitMemberExpr(ParseTreeNode node, Expression targetExpr, String memberName)\r\n   at Breeze.WebApi.ParseTreeVisitor.<>c__DisplayClass3.<VisitNode>b__0(ParseTreeNode n)\r\n   at System.Collections.Generic.List`1.ForEach(Action`1 action)\r\n   at Breeze.WebApi.ParseTreeVisitor.VisitNode(ParseTreeNode node)\r\n   at Breeze.WebApi.ParseTreeVisitor.VisitNode(ParseTreeNode node)\r\n   at Breeze.WebApi.ParseTreeVisitor.Parse(Type rootType, ParseTreeNode node)\r\n   at Breeze.WebApi.ExpressionTreeBuilder.Parse(Type rootType, String source)\r\n   at Breeze.WebApi.ODataActionFilter.BuildFilterFunc(String filterQueryString, Type elementType)\r\n   at Breeze.WebApi.ODataActionFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"}

As far as I can tell, this is the Breeze code that is generating the error.

protected virtual Expression VisitMemberExpr(ParseTreeNode node, Expression targetExpr, String memberName) {
  var targetType = targetExpr.Type;
  var member = targetType.GetMember(memberName).FirstOrDefault();
  if (member == null) {
    throw new Exception("Unable to locate member: " + memberName);
  }
  return Expression.MakeMemberAccess(targetExpr, member);
}

This is happening throughout my API, anywhere that I try to filter on an Expanded Property. Has anyone been successful at filtering on these?

UPDATE: Here is the Entity Query:

breeze.EntityQuery.from('ProductCollection') .where('PRODUCT_LINE.Descr', '==', 'Athena') .expand('PRODUCT_LINE');

AND in the APIController

[HttpGet] public IQueryable<COLLECTION> productCollection() { return _contextProvider.Context.COLLECTIONs; }

The Context Definition:

public DbSet<COLLECTION> COLLECTIONs { get; set; }

And Finally the Class definitions

public partial class COLLECTION
{
    public COLLECTION()
    {
        this.PRODUCT_LINE = new HashSet<PRODUCT_LINE>();
    }

    public int ID { get; set; }
    public string Descr { get; set; }
    public string Code { get; set; }
    public string DISPLAY_HTML { get; set; }
    public Nullable<System.DateTime> CREATED { get; set; }
    public string CREATOR { get; set; }
    public Nullable<System.DateTime> LAST_MODIFIED { get; set; }
    public string LAST_USER { get; set; }
    public string DEFAULT_IMAGE_PATH { get; set; }
    public Nullable<bool> IS_DELETED { get; set; }

    public virtual ICollection<PRODUCT_LINE> PRODUCT_LINE { get; set; }
}

public partial class PRODUCT_LINE
{
    public PRODUCT_LINE()
    {
        this.PRICING_DOOR = new HashSet<PRICING_DOOR>();
        this.POSSIBLE_INSULATION = new HashSet<POSSIBLE_INSULATION>();
        this.POSSIBLE_WINDOW = new HashSet<POSSIBLE_WINDOW>();
        this.WINDOWs = new HashSet<WINDOW>();
    }

    public int ID { get; set; }
    public Nullable<int> CollectionID { get; set; }
    public string Code { get; set; }
    public string Descr { get; set; }
    public string LongDescr { get; set; }
    public string DISPLAY_HTML { get; set; }
    public Nullable<System.DateTime> CREATED { get; set; }
    public string CREATOR { get; set; }
    public Nullable<System.DateTime> LAST_MODIFIED { get; set; }
    public string LAST_USER { get; set; }
    public string DEFAULT_IMAGE_PATH { get; set; }
    public Nullable<bool> IS_DELETED { get; set; }
    public string Product_Code_Group { get; set; }
    public Nullable<int> DefaultInsulationId { get; set; }
    public Nullable<int> DefaultWindowId { get; set; }

    public virtual COLLECTION COLLECTION { get; set; }
    public virtual ICollection<PRICING_DOOR> PRICING_DOOR { get; set; }
    public virtual ICollection<POSSIBLE_INSULATION> POSSIBLE_INSULATION { get; set; }
    public virtual ICollection<POSSIBLE_WINDOW> POSSIBLE_WINDOW { get; set; }
    public virtual ICollection<WINDOW> WINDOWs { get; set; }
}

Thanks,

2
Please post a copy of your entity query. I believe the problem has to do with the fact you are trying to filter on a property in an expanded entity that has not yet been expanded, but if you can post your entity query I can help confirm (or deny : )) that - PW Kad
breeze.EntityQuery.from('ProductCollection') .orderBy('Descr') .where('PRODUCT_LINE.Descr', '==', 'Athena') .expand('PRODUCT_LINE'); - Almander
So ProductCollection has PRODUCT_LINE's which have a Descr? - PW Kad

2 Answers

1
votes

One thing about this that doesn't make sense to me - is your ProductCollection a collection of Product's or an entity of type ProductCollection?

Edit

In your ApiController you are naming ProductCollection as productCollection, is that on purpose or a typo? Also, your collection of PRODUCT_LINE's is called PRODUCT_LINE, which one would think you meant to name it PRODUCT_LINES. Last, your ForeignKey is nullable (CollectionId), are you sure it is not null?

0
votes

I was able to resolve this error. Somehow I had a reference to Breeze 1.1.2, which did not show that it had any updates in the Package Manager. I finally realized that if i searched for breeze, it found v 1.3.6 to be the current version (which is what i assumed the project was on anyway).

An update to the current version of breeze resolved the issue.

kadumel => thanks for your valuable input!