2

我收到错误消息:

Unable to locate member:

过滤扩展实体属性时。

这有效:

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

并返回:

[{"$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":[]}]}]

注意,那PRODUCT_LINE是 Expanded,并且有一个Descr属性。

现在,如果我更改要过滤的 URL,则会PRODUCT_LINE.Descr收到错误消息:

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

返回:

{"$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)"}

据我所知,这是生成错误的微风代码。

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);
}

这发生在我的 API 中,在我尝试过滤扩展属性的任何地方。有没有人成功过滤这些?

更新:这是实体查询:

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

在 APIController 中

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

上下文定义:

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

最后是类定义

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; }
}

谢谢,

4

2 回答 2

1

关于这一点的一件事对我来说没有意义 - 您的 ProductCollection 是 Product 的集合还是 ProductCollection 类型的实体?

编辑

在您的 ApiController 中,您将 ProductCollection 命名为 productCollection,这是故意还是错字?此外,您的 PRODUCT_LINE 集合称为 PRODUCT_LINE,有人会认为您打算将其命名为 PRODUCT_LINES。最后,您的 ForeignKey 可以为空(CollectionId),您确定它不为空吗?

于 2013-06-21T17:38:47.517 回答
0

我能够解决这个错误。不知何故,我引用了 Breeze 1.1.2,它没有显示它在包管理器中有任何更新。我终于意识到,如果我搜索微风,它会发现 v 1.3.6 是当前版本(这就是我认为该项目正在进行的版本)。

对当前版本的微风的更新解决了该问题。

kadumel => 感谢您的宝贵意见!

于 2013-06-24T15:29:19.490 回答