【问题标题】:Breeze 1.4.0 navigation property not workingBreeze 1.4.0 导航属性不起作用
【发布时间】:2013-08-14 17:13:54
【问题描述】:

我一直在努力让它工作很长一段时间,但仍然没有成功......

我有以下型号:

public class Master
{
    [Key]
    public int Id { get; set; }
    public int UserId { get; set; }
    public int Month { get; set; }
    public int Year { get; set; }
    public int Version { get; set; }

    public ICollection<Detail> DetailsList { get; set; }
}

public class Detail
{
    [Key]
    public int Id { get; set; }

    public string Description { get; set; }
    public decimal Amount { get; set; }
    public string Notes { get; set; }
}

我的控制器如下所示:

...
[HttpGet]
public string Metadata()
{
    return _contextProvider.Metadata();
}


[HttpGet]
public IQueryable<Master> Masters()
{
   return _contextProvider.Context.Masters.Include("DetailsList");
}
...

在客户端我有这样的查询:

...
var query = EntityQuery.from('Masters').expand("DetailsList");

return manager.executeQuery(query)
    .then(querySucceeded)
    .fail(queryFailed);

function querySucceeded(data) {
    var master = data.results[0];

    if (masterObservable) {
        masterObservable(master);
    }
}
...

我遇到的问题是 DetailsList 属性在主对象中不存在,即使我可以在从服务器返回的 JSON 中看到它。 如果我在微风中设置 hasServerMetadata: true 。DataService 该对象将具有该属性,但显然它不再使用元数据。 这段代码过去在 1.1.3 版中运行良好,但自从我升级到 1.4.0 后它不再运行。我也尝试了 1.4.1,但没有运气。 我假设它与元数据有关,但我无法弄清楚我缺少什么才能让它再次工作。

【问题讨论】:

    标签: breeze


    【解决方案1】:

    您必须在 Detail 实体中定义一个外键,因为 Breeze 关联需要外键:

    public class Detail
    {
        [Key]
        public int Id { get; set; }
    
        public string Description { get; set; }
        public decimal Amount { get; set; }
        public string Notes { get; set; }
    
        public int MasterId { get; set; }
        public Master Master { get; set; }
    }
    

    您可以在http://www.breezejs.com/documentation/navigation-properties 找到有关关联的更多信息。

    【讨论】:

    • 谢谢。这行得通。我在 Master 引用之前添加到 Detail 类中,但我缺少 MasterId。
    猜你喜欢
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多