2013-06-21 20 views
2

過濾我收到錯誤:微風API錯誤無法找到成員:當上展開實體

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擴大,並且有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中,我嘗試在擴展屬性上進行篩選。有沒有人成功地過濾這些?

UPDATE: 這裏是實體查詢:

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

感謝,

+0

請發佈實體查詢的副本。我相信這個問題與你試圖篩選尚未擴展的擴展實體中的屬性有關,但如果你可以發佈實體查詢,我可以幫助確認(或拒絕:)) –

+0

' ('PRODUCT_LINE') .orderBy('Descr') .where('PRODUCT_LINE.Descr','==','Athena') .expand('PRODUCT_LINE');' – Almander

+0

所以ProductCollection有PRODUCT_LINE有Descr? –

回答

0

我能夠解決這個錯誤。不知何故,我有一個參考Breeze 1.1.2,它沒有表明它在包管理器中有任何更新。我終於意識到,如果我搜索微風,它會發現v 1.3.6是當前版本(這是我認爲該項目是在任何方面)。

對當前版本的微風的更新解決了問題。

kadumel =>感謝您的寶貴意見!

1

一件事這是沒有任何意義,我 - 是你ProductCollection產品的集合或類型ProductCollection的實體?

編輯

在你ApiController你命名ProductCollection爲productCollection,是故意還是一個錯字?此外,您收集的PRODUCT_LINE被稱爲PRODUCT_LINE,您可以認爲您想將其命名爲PRODUCT_LINES。最後,你的ForeignKey可以爲空(CollectionId),你確定它不是null嗎?

+0

它確實有一個名爲Descr的字段,我知道名稱很混亂,它是一個產品集合(PRODUCT_LINES)。我將定義添加到原始帖子中。 ('PRODUCT_LINE.Descr','==','Athena') .expand('PRODUCT_LINE');' – Almander

+0

你和你一樣,還有錯誤:'query = breeze.EntityQuery.from('ProductCollection') 沒有使用camelCase作爲默認或任何正確的? –

+0

不,雖然有趣。我很早就遇到了一個錯誤camelCase \t \t function configureBreezeManager(){ //這導致錯誤,指出服務器「密鑰」和客戶端「密鑰」名稱不匹配(密鑰源自元數據.. 。) // breeze.NamingConvention.camelCase.setAsDefault(); var mgr = new breeze.EntityManager(config.remoteServiceName); model.configureMetadataStore(mgr.metadataStore); return mgr; } – Almander