Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 编辑:Breeze JS忽略EF6导航属性;定义外键_Entity Framework_Breeze - Fatal编程技术网

Entity framework 编辑:Breeze JS忽略EF6导航属性;定义外键

Entity framework 编辑:Breeze JS忽略EF6导航属性;定义外键,entity-framework,breeze,Entity Framework,Breeze,我有三个实体:地区、地点和还款(实际上有十几个,但这些是重要的)。相关代码为: public class Site { [Key, Column(Order = 0)] public int DistrictId { get; set; } [Key, Column(Order = 1)] public int SiteId { get; set; } public string Name { get; set; } public virtu

我有三个实体:地区、地点和还款(实际上有十几个,但这些是重要的)。相关代码为:

public class Site 
{
    [Key, Column(Order = 0)]
    public int DistrictId { get; set; }
    [Key, Column(Order = 1)]
    public int SiteId { get; set; }

    public string Name { get; set; }

    public virtual District District { get; set; }
}

public class District 
{
    public int DistrictId { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Repayment> Repayments { get; set; }
}

public class Repayment 
{
    [Key, Column(Order = 0)]
    public int DistrictId { get; set; }
    [Key, Column(Order = 1)]
    public int RepaymentId { get; set; }

    public string Name { get; set; }

    [InverseProperty("Repayments")]
    [ForeignKey("DistrictId")]
    public virtual District District { get; set; }
}
以下是如何在两个实体中定义捷运局的资产净值属性:

偿还资产净值财产:

        {
            "name": "District",
            "relationship": "Self.Repayment_District",
            "fromRole": "Repayment_District_Source",
            "toRole": "Repayment_District_Target"
        },
        {
            "name": "District",
            "relationship": "Self.SeasonClient_District",
            "fromRole": "SeasonClient_District_Source",
            "toRole": "SeasonClient_District_Target"
        },
季度客户资产净值属性:

        {
            "name": "District",
            "relationship": "Self.Repayment_District",
            "fromRole": "Repayment_District_Source",
            "toRole": "Repayment_District_Target"
        },
        {
            "name": "District",
            "relationship": "Self.SeasonClient_District",
            "fromRole": "SeasonClient_District_Source",
            "toRole": "SeasonClient_District_Target"
        },
以下是地区关系定义:

        {
        "name": "SeasonClient_District",
        "end": [{
            "role": "SeasonClient_District_Source",
            "type": "Edm.Self.SeasonClient",
            "multiplicity": "*"
        },
        {
            "role": "SeasonClient_District_Target",
            "type": "Edm.Self.District",
            "multiplicity": "1",
            "onDelete": {
                "action": "Cascade"
            }
        }],
        "referentialConstraint": {
            "principal": {
                "role": "SeasonClient_District_Target",
                "propertyRef": {
                    "name": "DistrictId"
                }
            },
            "dependent": {
                "role": "SeasonClient_District_Source",
                "propertyRef": {
                    "name": "DistrictId"
                }
            }
        }
    },
与还款关系定义相同(如果将“季节客户”替换为“还款”)


有什么想法吗?

J也有类似的问题。2014年6月(当时所有最新的LIB),以下客户端代码起作用:

        return EntityQuery.from('FlowCharts')
        .withParameters({ flowChartId: 1 })
        .expand('Nodes.NodeFunction.NodeFunctionParameters, Connections')
        .using(manager).execute()
        .then(querySucceeded)
        .catch(_queryFailed);
但不是现在(2015年2月-更新到最新libs后)。将相关实体名称改为小写有帮助(请阅读@Ward调试提示):

希望能有帮助。
Grzech

除非我错过了,否则您没有向我们展示客户机上的相关Breeze元数据。你可能认为你有。但您实际上向我们展示了服务器端EF模型元数据。Breeze元数据导航属性描述符中没有“fromRole”。请查看文档中的。如果没有帮助,请返回相关的Breeze客户端元数据。感谢您的提示,@Ward,您是对的,我以为我给了您Breeze元数据。对不起,我错过了调试的那一页。我会处理一下,然后再打给你。我的第一次尝试是data.query.entityManager对象为null(data.query不为null),因此我似乎无法访问metadatastore,但我会看看我能想出什么。再次感谢。@ward,根据您的建议,我一直在调试微风元数据。如果有帮助的话,我可以发布它,但是我正在寻找的导航属性显然不包括在地区实体中(反向属性包括在还款实体中)。因此,我知道:1)服务器上的关系是正确的,而客户端上的关系是不正确的。我推断,这意味着从服务器发送的元数据没有正确格式化为Breeze,尽管我认为它“看起来”是正确的。我试过……同时使用FluentAPI和数据注释,但似乎没有什么不同。Breeze从服务器获取的元数据不会更改,关系也不会传播到客户端实体。是否可能对breeze端的实体/关系的数量有硬限制?My shop希望为其所有操作使用一个dbContext,因此元数据包括许多此项目未使用的实体和关系。提前谢谢你的建议,没有限制。但是,您(和您的API)可能会从一个简单的策略中受益,该策略可以减少模型(和元数据)的大小,而不会影响服务器团队对单一、全面的
DbContext
的需求。开局?创建
DbContext
的子类,隐藏您不想公开的内容。如果愿意,您可以将其用于元数据生成,甚至用于自己的api。它没有任何逻辑性,不会以任何方式妨碍您的团队。谢谢。这并没有解决我的问题(实际上它最近消失了,可能是由于模型中的其他更改)。但我一定会记住这一点。谢谢。@Grzech正在描述我们所做的更改,该更改强制执行了
expand
子句中的属性拼写必须与环境
NamingConvention
一致的规则。在此之前,我们没有强制执行该规则,而且,很偶然地,PascalCase属性名称在
expand
子句中工作,而它们本应如此。
        return EntityQuery.from('flowCharts')
        .withParameters({ flowChartId: 1 })
        .expand('nodes.nodeFunction.nodeFunctionParameters, connections')
        .using(manager).execute()
        .then(querySucceeded)
        .catch(_queryFailed);