我的breeze实体子节点不会扩展的任何明显原因?

时间:2014-06-21 08:41:01

标签: angularjs asp.net-web-api breeze hottowel breeze-sharp

我无法弄清楚为什么我的子节点为空或者计数为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; }
}

子节点属性&#34; CurrentMilestone&#34;回来了

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; }
}

子节点属性&#34;联系人&#34;即使有有效的匹配数据,也会返回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&amp;

在Fiddler中,子节点没有扩展。

1 个答案:

答案 0 :(得分:1)

想出来......

将Controller从ReadOnly更改为非readonly。

[HttpGet]
public IQueryable<Project> Projects()
{
    return _contextProvider.QueryAllReadOnly<Project>();
}

[HttpGet]
public IQueryable<Project> Projects()
{
    return _contextProvider.QueryAll<Project>();
}