【问题标题】:Multiplicity is not valid in Role Code First多重性在角色代码优先中无效
【发布时间】:2017-12-16 12:51:19
【问题描述】:

Books.cs

public class Books
    {
        public int BookId { get; set; }
        public int AuthorId { get; set; }
        public int CategoryId { get; set; }
        public int PublishinHouseId { get; set; }
        public string IsbnNo { get; set; }
        public string BookName { get; set; }
        public int NumberOfPages { get; set; }
        public string Location { get; set; }
        public virtual Authors Author { get; set; }
        public virtual  Categories Category { get; set; }
        public virtual PublishingHouses PublishingHouse { get; set; }

        public virtual ICollection<Borrowers> Borrowers { get; set; }
    }

Students.cs

public class Students
    {
        public int StudentId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int GenderId { get; set; }
        public  int DepartmentId { get; set; }
        public DateTime DateOfBirth { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
        public virtual Genders Gender { get; set; }
        public  virtual Departments Department { get; set; }

        public virtual ICollection<Borrowers> Borrowers { get; set; }
    }

Borrowers.cs

public class Borrowers
    {
        public int BorrowerId { get; set; }
        public int BookId { get; set; }
        public int StudentId { get; set; }
        public DateTime DateGiven { get; set; }
        public DateTime DateReceived { get; set; }
        public virtual Books Book { get; set; }
        public  virtual Students Student { get;set ;}
    }

BorrowerMap.cs

public BorrowerMap()
        {
            //Primary Key
            this.HasKey(t => t.BorrowerId);
            //Property
            this.Property(t => t.BorrowerId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            this.Property(t => t.DateGiven).IsRequired().HasColumnType("Date");
            this.Property(t => t.DateReceived).IsRequired().HasColumnType("Date");          
            this.ToTable("Borrowers");
            this.Property(t => t.BorrowerId).HasColumnName("BorrowerId");
            this.Property(t => t.BookId).HasColumnName("BookId");
            this.Property(t => t.StudentId).HasColumnName("StudentId");
            this.Property(t => t.DateGiven).HasColumnName("DateGiven");
            this.Property(t => t.DateReceived).HasColumnName("DateReceived");            
            this.HasRequired(p => p.Book).WithMany(p => p.Borrowers).HasForeignKey(f => f.BorrowerId);
            this.HasRequired(p => p.Student).WithMany(p => p.Borrowers).HasForeignKey(f => f.StudentId);
        }

下一步> 包管理器控制台

PM> Add-Migration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following parameters:
Name: MvcDbContext

错误:

在模型生成过程中检测到一个或多个验证错误:

Borrowers_Book_Source: : 多重性在角色中无效 关系“Borrowers_Book”中的“Borrowers_Book_Source”。因为 Dependent Role 是指关键属性,上界 从属角色的多重性必须为“1”。 请帮帮我?

【问题讨论】:

    标签: asp.net asp.net-mvc-4 ef-code-first migration entity-framework-migrations


    【解决方案1】:

    问题来自 Visual Studio。 祝你好运。

    【讨论】:

      猜你喜欢
      • 2014-10-04
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 2014-02-14
      • 1970-01-01
      相关资源
      最近更新 更多