C# OData$expand产生奇数错误

C# OData$expand产生奇数错误,c#,entity-framework,odata,asp.net-web-api-odata,C#,Entity Framework,Odata,Asp.net Web Api Odata,当我尝试将OData查询与$expand一起使用时,会产生以下错误: DbIsOfExpression requires an expression argument with a polymorphic result type that is compatible with the type argument. 我不确定我做错了什么,谷歌也没有真正揭示出错误背后的原因。该项目的所有参考都很好,所有其他OData查询都按预期工作 以下是相关的数据模型: public class ViewLin

当我尝试将OData查询与$expand一起使用时,会产生以下错误:

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; }
公共类视图链接
{
公共字符串重写名{get;set;}
公共字符串重写说明{get;set;}
公共bool IsActive{get;set;}
public int ViewLinkID{get;set;}
公共可为空的ViewID{get;set;}
公共可为空的LinkID{get;set;}
公共可空CreatedByID{get;set;}
公共虚拟视图{get;set;}
公共虚拟链接{get;set;}
}
公共部分类视图
{
公共可为空的学校ID{get;set;}
公共字符串ViewName{get;set;}
public int ViewID{get;set;}
公共可为空的ViewTypeID{get;set;}
公共可为空的TeacherID{get;set;}
公共虚拟ViewType ViewType{get;set;}
}

public分部类ViewType
{
公共字符串类型名{get;set;}
公共可空优先级{get;set;}
public int ViewTypeID{get;set;}
}
尝试使用以下OData查询时产生错误:

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

有什么地方我需要换环境吗?我只想在我做错的事情背后被引导到正确的方向,并了解这里正在发生的事情。我不想在以后的项目中继续出现这种错误

如果还有其他需要的东西,我会尽我所能去做

编辑:


我正在使用Web API OData。

视图和视图类型之间的关系是什么?在代码中,ViewType似乎是View的导航属性。如果是这样,查询应该是……?$expand=View($expand=ViewType)

它是否与ASP.NET Web API OData有关?还有不同的
WCF数据服务
,最好在您的问题中指定它。这表明至少有一种类型具有您应该显式查询的子类型。ViewType是一个导航属性。我尝试了您的查询,但收到以下错误:“术语‘View($expand=ViewType)’在$select或$expand表达式中无效。对不起,我错过了答案中的“?”。我已经编辑过了。如果还有其他问题,可以参考本文给出的详细实现和请求URL$select和$expand。
public partial class ViewType
{
    public string TypeName { get; set; }

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

    public int ViewTypeID { get; set; }
}