Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.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
C# .NET MVC oData将导航属性绑定到2个实体集_C#_Asp.net Mvc_Entity Framework_Odata - Fatal编程技术网

C# .NET MVC oData将导航属性绑定到2个实体集

C# .NET MVC oData将导航属性绑定到2个实体集,c#,asp.net-mvc,entity-framework,odata,C#,Asp.net Mvc,Entity Framework,Odata,我是.NETMVC的新手,第一次尝试创建ODataWeb服务。我有3个使用实体框架引用的表:组、子组和链接 我对3个表使用了现成的VisualStudio oData EF创建,而Groups web服务似乎运行良好。但是,“子组”表显示以下错误: Cannot automatically bind the navigation property 'SubGroups' on entity type 'Quick_Links.Models.Group' for the source entity

我是.NETMVC的新手,第一次尝试创建ODataWeb服务。我有3个使用实体框架引用的表:组、子组和链接

我对3个表使用了现成的VisualStudio oData EF创建,而Groups web服务似乎运行良好。但是,“子组”表显示以下错误:

Cannot automatically bind the navigation property 'SubGroups' on entity type 'Quick_Links.Models.Group' for the source entity set 'Groups' because there are two or more matching target entity sets. 
我的模型没有改变VS生成的模型,它们看起来如下所示:

组:

namespace Quick_Links.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;

public partial class Group
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Group()
    {
        SubGroups = new HashSet<SubGroup>();
    }

    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int GroupID { get; set; }

    public bool? GroupActive { get; set; }

    [StringLength(50)]
    public string GroupName { get; set; }

    [StringLength(50)]
    public string GroupSecurity { get; set; }

    [StringLength(50)]
    public string GroupAdmin { get; set; }

    [StringLength(50)]
    public string UpdateByEID { get; set; }

    public DateTime? UpdateDatetime { get; set; }

    [StringLength(50)]
    public string CreateByEID { get; set; }

    public DateTime? CreateDatetime { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<SubGroup> SubGroups { get; set; }
}
}
名称空间快速链接.Models
{
使用制度;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.ComponentModel.DataAnnotations.Schema;
使用System.Data.Entity.Spatial;
公共部分类组
{
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInConstructors”)]
公共组()
{
SubGroups=新HashSet();
}
[数据库生成(DatabaseGeneratedOption.None)]
public int GroupID{get;set;}
公共bool?GroupActive{get;set;}
[长度(50)]
公共字符串组名{get;set;}
[长度(50)]
公共字符串GroupSecurity{get;set;}
[长度(50)]
公共字符串GroupAdmin{get;set;}
[长度(50)]
公共字符串UpdateById{get;set;}
公共日期时间?UpdateDatetime{get;set;}
[长度(50)]
公共字符串CreateByEID{get;set;}
公共日期时间?CreateDatetime{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection子组{get;set;}
}
}
分组:

namespace Quick_Links.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;

public partial class SubGroup
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public SubGroup()
    {
        Links = new HashSet<Link>();
    }

    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int SubGroupID { get; set; }

    public bool? SubGroupActive { get; set; }

    public int? GroupID { get; set; }

    [StringLength(50)]
    public string SubGroupName { get; set; }

    public int? SubGroupOrder { get; set; }

    [StringLength(50)]
    public string SubGroupSecurity { get; set; }

    [StringLength(50)]
    public string UpdateByEID { get; set; }

    public DateTime? UpdateDatetime { get; set; }

    [StringLength(50)]
    public string CreateByEID { get; set; }

    public DateTime? CreateDatetime { get; set; }

    public virtual Group Group { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Link> Links { get; set; }
}
}
名称空间快速链接.Models
{
使用制度;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.ComponentModel.DataAnnotations.Schema;
使用System.Data.Entity.Spatial;
公共部分类子群
{
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInConstructors”)]
公共分组()
{
Links=newhashset();
}
[数据库生成(DatabaseGeneratedOption.None)]
公共int子类ID{get;set;}
公共布尔?子活动{get;set;}
public int?GroupID{get;set;}
[长度(50)]
公共字符串子组名称{get;set;}
公共int?子顺序{get;set;}
[长度(50)]
公共字符串安全性{get;set;}
[长度(50)]
公共字符串UpdateById{get;set;}
公共日期时间?UpdateDatetime{get;set;}
[长度(50)]
公共字符串CreateByEID{get;set;}
公共日期时间?CreateDatetime{get;set;}
公共虚拟组{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection链接{get;set;}
}
}
如果需要,我可以发布链接模型,但我认为这与组/子组是同一个问题

任何帮助都将不胜感激

编辑:这是我的数据集:

namespace Quick_Links.Models
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

public partial class QuickLinks : DbContext
{
    public QuickLinks()
        : base("name=QuickLinks")
    {
    }

    public virtual DbSet<Group> Groups { get; set; }
    public virtual DbSet<Link> Links { get; set; }
    public virtual DbSet<SubGroup> SubGroups { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Group>()
            .Property(e => e.GroupName)
            .IsUnicode(false);

        modelBuilder.Entity<Group>()
            .Property(e => e.GroupSecurity)
            .IsUnicode(false);

        modelBuilder.Entity<Group>()
            .Property(e => e.GroupAdmin)
            .IsUnicode(false);

        modelBuilder.Entity<Group>()
            .Property(e => e.UpdateByEID)
            .IsUnicode(false);

        modelBuilder.Entity<Group>()
            .Property(e => e.CreateByEID)
            .IsUnicode(false);

        modelBuilder.Entity<Link>()
            .Property(e => e.LinkName)
            .IsUnicode(false);

        modelBuilder.Entity<Link>()
            .Property(e => e.LinkURL)
            .IsUnicode(false);

        modelBuilder.Entity<Link>()
            .Property(e => e.LinkSecurity)
            .IsUnicode(false);

        modelBuilder.Entity<Link>()
            .Property(e => e.UpdateByEID)
            .IsUnicode(false);

        modelBuilder.Entity<Link>()
            .Property(e => e.CreateByEID)
            .IsUnicode(false);

        modelBuilder.Entity<SubGroup>()
            .Property(e => e.SubGroupName)
            .IsUnicode(false);

        modelBuilder.Entity<SubGroup>()
            .Property(e => e.SubGroupSecurity)
            .IsUnicode(false);

        modelBuilder.Entity<SubGroup>()
            .Property(e => e.UpdateByEID)
            .IsUnicode(false);

        modelBuilder.Entity<SubGroup>()
            .Property(e => e.CreateByEID)
            .IsUnicode(false);
    }
}
}
名称空间快速链接.Models
{
使用制度;
使用System.Data.Entity;
使用System.ComponentModel.DataAnnotations.Schema;
使用System.Linq;
公共部分类快速链接:DbContext
{
公共快速链接()
:base(“name=QuickLinks”)
{
}
公共虚拟数据库集组{get;set;}
公共虚拟数据库集链接{get;set;}
公共虚拟数据库集子组{get;set;}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Entity()
.Property(e=>e.GroupName)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.GroupSecurity)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.GroupAdmin)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.updateById)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.CreateByEID)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.LinkName)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.LinkURL)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.LinkSecurity)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.updateById)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.CreateByEID)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.name)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.security)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.updateById)
.IsUnicode(假);
modelBuilder.Entity()
.Property(e=>e.CreateByEID)
.IsUnicode(假);
}
}
}

这是一个错误,在我的WebAPIConfig中引用了错误的实体集。我将其更新为以下内容以修复此问题:

builder.EntitySet<Group>("Groups");
        builder.EntitySet<SubGroup>("SubGroups");
        builder.EntitySet<Link>("Links"); 
builder.EntitySet(“组”);
builder.EntitySet(“子组”);
builder.EntitySet(“链接”);