2014-09-05 55 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