我试图通过我的odata WCF 服务获取对象的属性,但是当我在特定属性上使用$ expand时,它似乎是" null&#34 ;。但是,在另一个属性中,我有该对象的Id(使用Entityframework),在那里你可以看到Id不是空的。
型号:
[Table("Approval"), DataContract, IgnoreProperties("Status", "Id")]
public class Approval : BaseEntity
{
...
[DataMember]
public Guid? ApproverId { get; set; }
[DataMember, ForeignKey("ApproverId")]
public virtual User Approver { get; set; }
[DataMember]
public virtual Request Request { get; set; }
}
[Table("Request"), DataContract, DataServiceKey("Id")]
public class Request : BaseEntity
{
...
[DataMember]
public Guid? LastModifiedById { get; set; }
[DataMember, ForeignKey("LastModifiedById")]
public virtual User LastModifiedBy { get; set; }
[DataMember]
public virtual Approval Approval { get; set; }
[DataMember, Required]
public Guid AbsenteeId { get; set; }
[DataMember, ForeignKey("AbsenteeId")]
public virtual User Absentee { get; set; }
[DataMember, Required]
public Guid AbsenceTypeId { get; set; }
[DataMember, ForeignKey("AbsenceTypeId")]
public virtual AbsenceType AbsenceType { get; set; }
}
odata服务电话:
http://<servername>/DataService.svc/Approvals?&$format=json&$expand=Request,Request/Absentee,Request/LastModifiedBy,Request/AbsenceType,Approver&$skip=0&$top=1
返回结果:
{
"odata.metadata": "http://<servername>/DataService.svc/$metadata#Approvals",
"value": [
{
"Approver": null,
"Request": {
"LastModifiedBy": null,
"Absentee": null,
"AbsenceType": null,
...
"LastModifiedById": "6a1f8e79-99f5-e511-9444-0050568627d2",
"AbsenteeId": "6a1f8e79-99f5-e511-9444-0050568627d2",
"AbsenceTypeId": "fc7e8a5d-99f5-e511-9444-0050568627d2"
},
...
"ApproverId": null
}
]
}
在这种情况下,值 - &gt;请求 - &gt; LastModifiedBy / Absentee / AbsenceType不应为空!!!!
有谁知道我错过了什么/做错了什么?