微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

元数据集合中不存在身份为“Venue_Meets_Source”的成员

如何解决元数据集合中不存在身份为“Venue_Meets_Source”的成员

我的 MVC 应用程序目前存在一个问题,如果我尝试使用场所保存会议,我的应用程序会崩溃并显示以下错误:元数据集合中不存在标识为“Venue_Meets_Source”的成员。

我怀疑这与 Entity Framework 如何根据我提供的类创建我的数据库有关,但我看不到问题。

尝试研究该问题的注意事项:我没有使用 Fluent,没有触发器会导致问题,因为我没有 EF 创建的触发器。

见面班

public class Meet
    {
        public int Id { get; set; }
        [display(Name ="Meet Name")]
        public string MeetName { get; set; }
        public string Date { get; set; }
        [display(Name = "Pool Length (Metres)")]
        public string PoolLength { get; set; }
        public int VenueId { get; set; }
        [display(Name = "Venue")]
        public virtual Venue Venue { get; set; }
        public virtual ICollection<Event> Events { get; set; }
        
    }

场地班

 public class Venue
    {
        public int Id { get; set; }

        public string VenueName { get; set; }

        public string Address { get; set; }

        public virtual ICollection<Meet> Meets { get; set; }

    }

在前端,Meet 有一个下拉菜单,可以为对象添加地点

初始创建迁移

namespace MVCWebAssignment1.Migrations.MigrationContext
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Events",c => new
                    {
                        Id = c.Int(nullable: false,identity: true),AgeRange = c.String(),Gender = c.String(),distance = c.String(),Swimmingstroke = c.String(),MeetId = c.Int(nullable: false),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Meets",t => t.MeetId,cascadeDelete: true)
                .Index(t => t.MeetId);
            
            CreateTable(
                "dbo.Meets",MeetName = c.String(),Date = c.String(),PoolLength = c.String(),VenueId = c.Int(nullable: false),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Venues",t => t.VenueId,cascadeDelete: true)
                .Index(t => t.VenueId);
            
            CreateTable(
                "dbo.Venues",VenueName = c.String(),Address = c.String(),})
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Rounds",EventId = c.Int(nullable: false),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Events",t => t.EventId,cascadeDelete: true)
                .Index(t => t.EventId);
            
            CreateTable(
                "dbo.Lanes",SwimmerId = c.String(maxLength: 128),FinishTime = c.String(),LaneComment = c.String(),round_Id = c.Int(),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Rounds",t => t.round_Id)
                .ForeignKey("dbo.AspNetUsers",t => t.SwimmerId)
                .Index(t => t.SwimmerId)
                .Index(t => t.round_Id);
            
            CreateTable(
                "dbo.AspNetUsers",c => new
                    {
                        Id = c.String(nullable: false,maxLength: 128),Name = c.String(),DateOfBirth = c.String(),IsAllowedToSwim = c.Boolean(nullable: false),Email = c.String(maxLength: 256),EmailConfirmed = c.Boolean(nullable: false),PasswordHash = c.String(),SecurityStamp = c.String(),PhoneNumber = c.String(),PhoneNumberConfirmed = c.Boolean(nullable: false),TwoFactorEnabled = c.Boolean(nullable: false),LockoutEndDateUtc = c.DateTime(),LockoutEnabled = c.Boolean(nullable: false),AccessFailedCount = c.Int(nullable: false),UserName = c.String(nullable: false,maxLength: 256),FamilyGroup_FamilyGroupId = c.Int(),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.FamilyGroups",t => t.FamilyGroup_FamilyGroupId)
                .Index(t => t.UserName,unique: true,name: "UserNameIndex")
                .Index(t => t.FamilyGroup_FamilyGroupId);
            
            CreateTable(
                "dbo.AspNetUserClaims",UserId = c.String(nullable: false,ClaimType = c.String(),ClaimValue = c.String(),})
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers",t => t.UserId,cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.FamilyGroups",c => new
                    {
                        FamilyGroupId = c.Int(nullable: false,GroupName = c.String(),})
                .PrimaryKey(t => t.FamilyGroupId);
            
            CreateTable(
                "dbo.AspNetUserLogins",c => new
                    {
                        LoginProvider = c.String(nullable: false,ProviderKey = c.String(nullable: false,})
                .PrimaryKey(t => new { t.LoginProvider,t.ProviderKey,t.UserId })
                .ForeignKey("dbo.AspNetUsers",cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.AspNetUserRoles",c => new
                    {
                        UserId = c.String(nullable: false,RoleId = c.String(nullable: false,})
                .PrimaryKey(t => new { t.UserId,t.RoleId })
                .ForeignKey("dbo.AspNetUsers",cascadeDelete: true)
                .ForeignKey("dbo.AspNetRoles",t => t.RoleId,cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.AspNetRoles",Name = c.String(nullable: false,})
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name,name: "RoleNameIndex");
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AspNetUserRoles","RoleId","dbo.AspNetRoles");
            DropForeignKey("dbo.Lanes","SwimmerId","dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles","UserId","dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins","dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUsers","FamilyGroup_FamilyGroupId","dbo.FamilyGroups");
            DropForeignKey("dbo.AspNetUserClaims","dbo.AspNetUsers");
            DropForeignKey("dbo.Lanes","round_Id","dbo.Rounds");
            DropForeignKey("dbo.Rounds","EventId","dbo.Events");
            DropForeignKey("dbo.Meets","VenueId","dbo.Venues");
            DropForeignKey("dbo.Events","MeetId","dbo.Meets");
            DropIndex("dbo.AspNetRoles","RoleNameIndex");
            DropIndex("dbo.AspNetUserRoles",new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles",new[] { "UserId" });
            DropIndex("dbo.AspNetUserLogins",new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims",new[] { "UserId" });
            DropIndex("dbo.AspNetUsers",new[] { "FamilyGroup_FamilyGroupId" });
            DropIndex("dbo.AspNetUsers","UserNameIndex");
            DropIndex("dbo.Lanes",new[] { "round_Id" });
            DropIndex("dbo.Lanes",new[] { "SwimmerId" });
            DropIndex("dbo.Rounds",new[] { "EventId" });
            DropIndex("dbo.Meets",new[] { "VenueId" });
            DropIndex("dbo.Events",new[] { "MeetId" });
            DropTable("dbo.AspNetRoles");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.FamilyGroups");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.Lanes");
            DropTable("dbo.Rounds");
            DropTable("dbo.Venues");
            DropTable("dbo.Meets");
            DropTable("dbo.Events");
        }
    }
}

感谢指导!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。