0

当我尝试使用带有 $expand 的 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。

4

1 回答 1

0

View 和 ViewType 是什么关系?在您的代码中,似乎 ViewType 是 View 的导航属性。如果是这样,查询应该是 ....?$expand=View($expand=ViewType)。

于 2014-09-08T05:33:07.327 回答