我无法弄清楚为什么我的子节点为空或计数为 0,即使数据库中有关联的数据。
父类“项目”
public partial class Project
{
public Project()
public int Id { get; set; }
public string Name { get; set; }
public int ProjectOwnerId { get; set; }
public int CurrentMilestoneId { get; set; }
public int StatusId { get; set; }
public virtual Milestone CurrentMilestone { get; set; }
public virtual ProjectStatus Status { get; set; }
public virtual ICollection<ProjectContact> Contacts { get; set; }
public virtual ProjectAddress Address { get; set; }
}
子节点属性“CurrentMilestone”返回 null
public partial class Milestone
{
public int Id { get; set; }
public int MasterMilestoneId { get; set; }
public string Name { get; set; }
public virtual MasterMilestone MasterMilestone { get; set; }
public virtual ICollection<Project> Projects { get; set; }
}
即使存在有效的匹配数据,子节点属性“Contacts”也会返回一个 0 数组。
public partial class ProjectContact
{
public int Id { get; set; }
public int ProjectId { get; set; }
public int PersonId { get; set; }
public string Title { get; set; }
public virtual Person Person { get; set; }
public virtual Project Project { get; set; }
}
使用 HotTowel angular/breeze 我正在运行这个..
return EntityQuery.from("Projects")
.orderBy(orderBy)
.expand("currentMilestone.masterMilestone, projectOwnerCompany, contacts, address")
.using(self.manager).execute()
.then(querySucceeded, self._queryFailed);
function querySucceeded(data) {
projects = data.results;
return projects;
}
控制器:
[HttpGet]
public IQueryable<Project> Projects()
{
return _contextProvider.QueryAllReadOnly<Project>();
}
奇怪的是它们中的一些可以工作,比如 Status 可以工作,但 leaseStatus 不能(未显示,以相同的方式设置)而不扩展它。
只是为了添加更多信息,如果我对 API 运行它, ..../Projects?$expand=Status%2CCurrentMilestone%2CLeaseStatus%2CCurrentMilestone%2FMasterMilestone%2CContacts%2CContacts%2FPerson&
在 Fiddler 中,子节点没有展开。