OData-获取实体并加载导航属性的一项

时间:2019-02-06 22:59:26

标签: odata

我有实体人,并且有一系列地址。

public class Person {
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Adress> Adresses { get;set; }
    ....
}

我只想加载所有人员,并且只加载他们当前的地址(所以我想加载一个地址项;应该过滤旧地址)。我可以通过$ filter使用OData吗?

示例:

我收到了这个json

[{
  Id: 1,
  Name "Person1",
  Addresses: [
  {
     Id: 10,
     Address: "Street 1",
     Current: true 
  },
  {
     Id: 20,
     Address: "Street 2",
     Current: false 
  }]
},{
  Id: 2,
  Name "Person2",
  Addresses: [
  {
     Id: 100,
     Address: "Street 100",
     Current: true 
  },
  {
     Id: 200,
     Address: "Street 200",
     Current: false 
  }]
}]

我想获取所有人物,但仅使用当前地址,过滤其他地址:

[{
  Id: 1,
  Name "Person1",
  Addresses: [
  {
     Id: 10,
     Address: "Street 1",
     Current: true 
  }]
},{
  Id: 2,
  Name "Person2",
  Addresses: [
  {
     Id: 100,
     Address: "Street 100",
     Current: true 
  }]
}]

0 个答案:

没有答案