1

我在我的 .NET 4.5.1 WebAPI 项目中使用Swagger-Net,我的一个 API 调用导致 Swagger UI 在加载时永远旋转,然后返回以下错误。

在此处输入图像描述

具体来说,我发现[FromUri]与引用其他实体的复杂 EF 实体结合使用最终会导致这种情况。

[HttpPost]
public APIResponse CreateSchool([FromUri]School school)
{
  // save school object to db
}

public partial class School  : IAuditableEntity,IEntity
{
    public School()
    {
        this.Affiliations = new HashSet<Affiliation>();
        this.SchoolAccreditations = new HashSet<SchoolAccreditation>();
        this.SchoolAdultRoles = new HashSet<SchoolAdultRole>();
        this.SchoolCareOptions = new HashSet<SchoolCareOption>();
        this.SchoolDailySessions = new HashSet<SchoolDailySession>();
        this.SchoolEligibilityRequirements = new HashSet<SchoolEligibilityRequirement>();
        // ...more hashsets

        [DataMember]
            public int SchoolID { get; set; }
        [DataMember]
            public string Name { get; set; }
        [DataMember]
            public bool Active { get; set; }
        //...more properties
    }
}

有没有办法仍然使用FromUri和EF模型?还是我需要更改我的 API 调用签名?

4

0 回答 0