BreezeJs-当两个外键与公共实体相关时使用expand()

BreezeJs-当两个外键与公共实体相关时使用expand(),breeze,expand,entities,Breeze,Expand,Entities,比如说,我有两个实体,移动id、fromLocationId、toLocationId、fromLocationId和toLocationId是第二个实体位置id name的两个外键。我想编写一个Breeze查询,检索所有位置名称与fromLocationId和toLocationId相关的移动。到目前为止,我得到的是: var query=breeze.EntityQuery'movement'。展开'location' 例如,当我调试它并检查第一条记录时,我发现它有location和loca

比如说,我有两个实体,移动id、fromLocationId、toLocationId、fromLocationId和toLocationId是第二个实体位置id name的两个外键。我想编写一个Breeze查询,检索所有位置名称与fromLocationId和toLocationId相关的移动。到目前为止,我得到的是:

var query=breeze.EntityQuery'movement'。展开'location'

例如,当我调试它并检查第一条记录时,我发现它有location和location1属性。我可以从数据[0].location.name中检索fromLocationId的位置名称,但不能对toLocationId的位置名称进行检索,因为位置1为空。我甚至尝试了var query=breeze.EntityQuery'movement'。扩展'location,location1';但它仍然不起作用

有没有办法解决这个问题?提前谢谢

编辑

以下是.NET类:

[Table("Location")]
public partial class Location
{
    public Location()
    {
        Movements = new HashSet<Movement>();
        Movements1 = new HashSet<Movement>();
    }

    public int Id { get; set; }

    [StringLength(250)]
    public string Name { get; set; }

    public virtual ICollection<Movement> Movements { get; set; }

    public virtual ICollection<Movement> Movements1 { get; set; }
}

[Table("Movement")]
public partial class Movement
{
    public int Id { get; set; }

    public int FromLocationId { get; set; }

    public int ToLocationId { get; set; }

    public virtual Location Location { get; set; }

    public virtual Location Location1 { get; set; }
}
在DbContext类中,关系如下所示:

        modelBuilder.Entity<Location>()
            .HasMany(e => e.Movements)
            .WithRequired(e => e.Location)
            .HasForeignKey(e => e.FromLocationId)
            .WillCascadeOnDelete(false);

        modelBuilder.Entity<Location>()
            .HasMany(e => e.Movements1)
            .WithRequired(e => e.Location1)
            .HasForeignKey(e => e.ToLocationId)
            .WillCascadeOnDelete(false);

谢谢。

好的,我知道我需要做什么了。以下是解决方案:

var query=breeze.EntityQuery'movement'。展开'location,location'

我想,Breeze对此的理解是,扩展中的第一个位置将与fromLocationId相关,第二个位置将与toLocationId相关。换句话说,添加与该公共实体相关的外键数量相同的实体


希望它能帮助别人。

我不这么认为。还有别的事情。服务器上导航属性的名称是什么?移动类型的元数据是什么?它到底是被称为移动还是被称为移动?正如问题所述,实体是服务器上的移动和位置。位置的属性是Id和Name,移动的属性是Id、FromLocationId和ToLocationId。属性FromLocationId和ToLocationId都是指向Location的外键。您似乎是对的,因为BreezeJs不会检索与这两个外键对应的所有名称。我该怎么办?你没有描述你的后端技术。您正在使用EF吗?@Ward:是的,我正在使用EF 1.6.1和Breeze WebApi2 1.5.2。我相信您需要两个导航属性才能与两个FK配合使用。它们可以从地点和地点命名吗?您还需要一些EF配置(属性或fluent API),以便EF知道哪个FK与哪个属性一起使用。向我们展示您的.NET类和fluent API配置(如果有)。