過濾我收到錯誤:微風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; }
}
感謝,
請發佈實體查詢的副本。我相信這個問題與你試圖篩選尚未擴展的擴展實體中的屬性有關,但如果你可以發佈實體查詢,我可以幫助確認(或拒絕:)) –
' ('PRODUCT_LINE') .orderBy('Descr') .where('PRODUCT_LINE.Descr','==','Athena') .expand('PRODUCT_LINE');' – Almander
所以ProductCollection有PRODUCT_LINE有Descr? –