ASP.NET Web API OData 5.3 中的新增功能

Microsoft

本主题介绍 ASP.NET Web API OData 5.3 的新增功能。

下载

运行时功能作为 NuGet 库上的 NuGet 包发布。 可以使用 NuGet 包管理器控制台安装或更新已发布的 NuGet 包:

Install-Package Microsoft.AspNet.OData -Version 5.3.0 
Install-Package Microsoft.AspNet.WebApi.OData -Version 5.3.0

文档

可以在 ASP.NET 网站上找到有关 ASP.NET Web API OData 教程和其他文档。

OData 核心库

对于 OData v4,Web API 现在使用 ODataLib 版本 6.5.0

ASP.NET Web API OData 5.3 中的新增功能

支持在 $expand 中$levels

可以在$expand查询中使用 $levels 查询选项。 例如:

http://example.com/Employees?$expand=Manager($levels=2)

此查询等效于:

http://example.com/Employees?$expand=Manager($expand=Manager))

支持开放实体类型

打开类型是一种结构化类型,它包含动态属性,以及类型定义中声明的任何属性。 开放类型使你可以为数据模型增加灵活性。 有关详细信息,请参阅 xxxx。

支持打开类型中的动态集合属性

以前,动态属性必须是单个值。 在 5.3 中,动态属性可以具有集合值。 例如,在以下 JSON 有效负载中, Emails 属性是动态属性,是字符串类型的集合:

{
   "Id": 1,
   "Name": "Ben",
   "Emails@odata.type": "#Collection(Edm.String)",
   "Emails": [
      "a@a.com",
      "b@b.com"
   ]
}

支持复杂类型的继承

现在,复杂类型可以从基类型继承。 例如,OData 服务可以定义以下复杂类型:

public abstract class Shape
{
    public bool HasBorder { get; set; }
}

public class Point
{
    public int X { get; set; }
    public int Y { get; set; }
}

public class Circle : Shape
{
    public Point Center { get; set; }
    public int Radius { get; set; }

    public override string ToString()
    {
        return "{" + Center.X + "," + Center.Y + "," + Radius + "}";
    }
}

public class Polygon : Shape
{
    public IList<Point> Vertexes { get; set; }
    public Polygon()
    {
        Vertexes = new List<Point>();
    }
}

下面是此示例的 EDM:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
  <edmx:DataServices>
    <Schema Namespace="ODataComplexTypeInheritanceSample" xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <ComplexType Name="Shape" Abstract="true">
        <Property Name="HasBorder" Type="Edm.Boolean" Nullable="false" />
      </ComplexType>
      <ComplexType Name="Polygon" BaseType="ODataComplexTypeInheritanceSample.Shape">
        <Property Name="Vertexes" Type="Collection(ODataComplexTypeInheritanceSample.Point)" />
      </ComplexType>
      <ComplexType Name="Point">
        <Property Name="X" Type="Edm.Int32" Nullable="false" />
        <Property Name="Y" Type="Edm.Int32" Nullable="false" />
      </ComplexType>
      <ComplexType Name="Circle" BaseType="ODataComplexTypeInheritanceSample.Shape">
        <Property Name="Center" Type="ODataComplexTypeInheritanceSample.Point" />
        <Property Name="Radius" Type="Edm.Int32" Nullable="false" />
      </ComplexType>
      <EntityContainer Name="Container">
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

有关详细信息,请参阅 OData 复杂类型继承示例

已知问题和重大更改

本部分介绍 ASP.NET Web API OData 5.3 中的已知问题和中断性变更。

OData v4

查询选项

问题:使用具有 $levels=max 的嵌套$expand会导致不正确的扩展深度。

例如,给定以下请求:

~/Entities(6)?$expand=P($levels=2;$expand=D($levels=max))

如果 MaxExpansionDepth 为 5,则此查询将导致扩展深度为 6。

Bug 修复和次要功能汇报

此版本还包括多个 bug 修复和次要功能更新。

ASP.NET Web API OData 5.3.1

在此版本中,我们对某些 AllowedFunctions 枚举进行了 bug 修复。 此版本没有任何其他 bug 修复或新功能。