2014-09-05 57 views
0

當我嘗試使用OData的查詢與$展開下面的錯誤產生:

DbIsOfExpression requires an expression argument with a polymorphic result type that is compatible with the type argument. 

我不知道我在做什麼錯了,谷歌不真正揭示了這個錯誤的背後。該項目的所有參考都很好,所有其他OData查詢都按預期工作。

這裏的是相關數據模型:

public class ViewLink 
{ 
    public string OverrideLinkName { get; set; } 

    public string OverrideDescription { get; set; } 

    public bool IsActive { get; set; } 

    public int ViewLinkID { get; set; } 

    public Nullable<int> ViewID { get; set; } 

    public Nullable<int> LinkID { get; set; } 

    public Nullable<int> CreatedByID { get; set; } 

    public virtual View View { get; set; } 

    public virtual Link Link { get; set; } 
} 

public partial class View 
{ 
    public Nullable<int> SchoolID { get; set; } 

    public string ViewName { get; set; } 

    public int ViewID { get; set; } 

    public Nullable<int> ViewTypeID { get; set; } 

    public Nullable<int> TeacherID { get; set; } 

    public virtual ViewType ViewType { get; set; } 

}

public partial class ViewType 
{ 
    public string TypeName { get; set; } 

    public Nullable<int> Priority { get; set; } 

    public int ViewTypeID { get; set; } 
} 

當我嘗試使用下面的OData查詢時產生的錯誤:

http://apilinkhere.com/api/viewlink?$top=1&$expand=View/ViewType

是我需要改變某處的設置?我只想在我做錯的背後朝着正確的方向領導,並且理解這裏發生的事情。我不想在未來的項目中繼續出現這個錯誤。

如果還有其他需要的東西,我會盡我所能來製作它。

編輯:

我正在使用Web API OData。

+0

它關心「ASP.NET Web API OData」嗎?還有'WCF數據服務'這是不同的,這將是很好的在你的問題中指定。 – 2014-09-05 20:24:21

+0

這表明至少有一種類型具有您應該明確查詢的子類型。 – 2014-09-05 20:28:46

回答

0

View和ViewType之間的關係是什麼?在你的代碼中,ViewType似乎是View的導航屬性。如果是這樣,查詢應該是....?$ expand = View($ expand = ViewType)。

+0

ViewType是一個導航屬性。我嘗試了您的查詢,但收到以下錯誤:「Term'View($ expand = ViewType)'在$ select或$ expand表達式中無效。」 – 2014-09-08 12:23:13

+0

對不起,我想念「?」在答案中。我編輯過它。如果還有其他問題,可以參考http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/SelectExpandDollarValueSample/。這給出了$ select和$ expand的詳細實現和請求URL。 – QianLi 2014-09-09 02:26:13