【问题标题】:Breeze doesn't populate collection navigation propertyBreeze 不填充集合导航属性
【发布时间】:2014-12-09 09:41:23
【问题描述】:

我有一个实体框架 6、数据库优先的模型,我在 BreezeController 后面查询它。我的问题是当我向控制器查询对象时,微风不会填充导航集合属性。它已定义,但它是空的。

这是服务器端(生成的)POCO 和 Breeze 控制器方法:

public partial class Inventory
{   
    public int Id { get; set; }
    ...
    public virtual ICollection<InstrumentReading> InstrumentReadings { get; set; }
}

public partial class InstrumentReading
{
    public int Id { get; set; }
    ...
    public Nullable<int> InventoryId { get; set; }
}

[BreezeController]
public class BreezeController : ApiController
{
    ....
    [HttpGet]
    public IQueryable<Inventory> Inventories([FromUri] int id)
    {
        var data = _repository.Inventories(id);
        return data;
    }
}

这就是我在 javascript 中查询它所做的:

        return EntityQuery.from('Inventories')
            .expand('InstrumentReadings') 
            .withParameters({ id: id })
            .toType('Inventory').using(self.manager)
            .execute().then(querySucceeded, self._queryFailed);

        function querySucceeded(data) {

            var entity = data.results[0];
            self.log('Retrieved [' + entityName + '] id ' + entity.id
                + ' from remote data source', entity, true);
            return entity;
        }

如果我在 FireBug 中查看对控制器调用的响应,一切都在那里,包括填充的导航属性:

但是为什么微风不能填充集合导航属性呢?

当我查看元数据存储时,据我所知,一切看起来都不错:

我真的不希望在检索库存后必须进行单独的往返来查询 InstrumentReadings。我认为微风应该为我做到这一点。

感谢您的帮助! 科里。

【问题讨论】:

    标签: javascript breeze entity-framework-6


    【解决方案1】:

    使用expand 查询方法eager load InstrumentReadings。

    return EntityQuery.from('Inventories')
        .expand('InstrumentReadings')  // <-- include the instrument readings
        .withParameters({ id: id })
        .using(self.manager)
        .execute()
        .then(querySucceeded, self._queryFailed);
    

    【讨论】:

    • 感谢您的回复。这似乎合乎逻辑,但没有任何区别。更新了 OP。
    【解决方案2】:

    我查看了其他帖子,并查看了外键是如何在子实体中定义的。原来实体上还有 3 个其他外键似乎混淆了 EF 和 Breeze。当我重构子实体以包含单个导航属性时,一切都开始工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多