Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
带有webapi的OData-导航属性_Odata_Breeze_Asp.net Web Api - Fatal编程技术网

带有webapi的OData-导航属性

带有webapi的OData-导航属性,odata,breeze,asp.net-web-api,Odata,Breeze,Asp.net Web Api,我正在编写基于WebApi asp.net的OData服务,我正在构建自己的EDM ODataModelBuilder builder = new ODataModelBuilder(); builder.Namespace = "Models"; EntitySetConfiguration<Incident> incident = builder.EntitySet<Incident>("Incidents"); i

我正在编写基于WebApi asp.net的OData服务,我正在构建自己的EDM

ODataModelBuilder builder = new ODataModelBuilder();

        builder.Namespace = "Models";

        EntitySetConfiguration<Incident> incident = builder.EntitySet<Incident>("Incidents");
        incident.EntityType.HasKey(c => c.IncidentID);
        incident.EntityType.Property(c => c.Name);
        incident.EntityType.Property(c => c.IncidentType);
        incident.EntityType.Property(c => c.Description);
        incident.HasIdLink(eic =>
        {
            return eic.GenerateSelfLink(false);
        }, false);

        var hasManyComments = incident.EntityType.HasMany(c => c.IncidentComments);
        incident.HasNavigationPropertyLink(hasManyComments, (z, y) =>
        {
            return z.GenerateNavigationPropertyLink(y, false);
        }, false);

        EntitySetConfiguration<IncidentComment> incidentComment = builder.EntitySet<IncidentComment>("IncidentComments");
        incidentComment.EntityType.HasKey(c => c.CommentID);
        incidentComment.EntityType.Property(c => c.IncidentID);
        incidentComment.EntityType.Property(c => c.Content);
        incidentComment.HasIdLink(eic =>
        {
            return eic.GenerateSelfLink(false);
        }, false);
ODataModelBuilder=new ODataModelBuilder();
builder.Namespace=“Models”;
EntitySetConfiguration事件=builder.EntitySet(“事件”);
incident.EntityType.HasKey(c=>c.IncidentID);
incident.EntityType.Property(c=>c.Name);
incident.EntityType.Property(c=>c.IncidentType);
incident.EntityType.Property(c=>c.Description);
事件。HasIdLink(eic=>
{
返回eic.GenerateSelfLink(false);
},假);
var hasManyComments=incident.EntityType.HasMany(c=>c.IncidentComments);
事件.HasNavigationPropertyLink(hasManyComments,(z,y)=>
{
返回z.GenerateNavigationPropertyLink(y,false);
},假);
EntitySetConfiguration incidentComment=builder.EntitySet(“IncidentComments”);
incidentComment.EntityType.HasKey(c=>c.CommentID);
incidentComment.EntityType.Property(c=>c.IncidentID);
incidentComment.EntityType.Property(c=>c.Content);
incidentComment.HasIdLink(eic=>
{
返回eic.GenerateSelfLink(false);
},假);

我作为客户端测试BreezeJS和wcf数据客户端。当我试图在网络中获取事件时,我看到事件属性和评论都被传递了。然而,在wcf客户端中,我得到了空的评论集合,而且对于Breeze测试,我怀疑元数据是不正确的,我遗漏了什么。。。问题可能在于ODataModelBuilder尚未处理外键的概念。因此,Breeze无法检索将fk链接到其相应导航属性的元数据。我们已经向微软指出了这一点,他们理解这一问题,但表示这一问题在以后的版本中才会得到解决。这类似于MS首次发布实体框架时出现的独立关联与外键关联的问题

为什么不使用ODataConventionModelBuilder?它会自动为您创建模型(示例):
ODataConventionModelBuilder modelBuilder=new-ODataConventionModelBuilder();var events=modelBuilder.EntitySet(“事件”);var comments=modelBuilder.EntitySet(“IncidentComment”)因为有些属性我不想公开,唯一的方法是添加ignoredatamember的属性。我希望有几种类型的客户端可以进行不同的连接,并且可以看到不同的数据集…但是要忽略属性,还可以执行类似以下操作
products.EntityType.ignore(prd=>prd.ReleaseDate)但它如何知道如何构建导航属性?基于哪些属性?有没有办法在微风中克服这一点?也许是微风中的一些配置?