Breeze扩展导航属性而不是填充数组

时间:2014-07-22 03:39:56

标签: asp.net-web-api breeze entity-framework-6

我正在使用带有Breeze和Entity Framework 6的Web API 2.我有以下模型。

 public class ScoreCard: EntityBase
{
    public string Title { get; set; }

    public virtual List<ScoreCardSection> Sections { get; set; }

    public String UserId { get; set; }

}
public class ScoreCardSection:EntityBase
{
    public string Title { get; set; }
    public int Index { get; set; }

    public long ScoreCardId { get; set; }

    public virtual List<ScoreCardQuestion> Questions { get; set; }
}

我想获取一张带有部分列表的记分卡。我使用expand执行EntityQuery并执行此URL:

/api/ScoreCards?$filter=Id%20eq%201L&$expand=Sections

我得到以下结果:

  [{"Title":"Catalyst Service Report","Sections":
[{"Title":"Worship","Index":0,"ScoreCardId":1,"Questions":null,"Id":1},
{"Title":"Message","Index":0,"ScoreCardId":1,"Questions":null,"Id":2},
{"Title":"Leader","Index":0,"ScoreCardId":1,"Questions":null,"Id":3},
{"Title":"Attendance","Index":0,"ScoreCardId":1,"Questions":null,"Id":4},
{"Title":"Security","Index":0,"ScoreCardId":1,"Questions":null,"Id":5}],
"UserId":"b9bd5256-dd18-4c1e-9907-dac9e7e4c01b","Id":1}]

到目前为止,这么好。现在我们解决了这个问题。当我在成功回调期间检查结果时,对象的sections属性是一个空数组,即使这些部分是在响应中发回的。

我在这里缺少什么?谢谢你提前。

1 个答案:

答案 0 :(得分:0)

好的,这个问题的解决方案似乎是几个小时的睡眠。

对于有同样问题的人来说,问题的第一部分是我在ScoreCardSection上没有ScoreCard的导航属性。一旦我添加,我得到一个“自我引用循环”错误。通过将BreezeControllerAttribute添加到我的控制器类来解决这个问题。

希望这对某人有帮助。

相关问题