【问题标题】:cannot share table no matching primary key无法共享表没有匹配的主键
【发布时间】:2014-11-28 02:20:40
【问题描述】:

实体类型 'Profile' 和 'Country' 不能共享表 'Countries',因为它们不在同一类型层次结构中,或者与匹配的主对象没有有效的一对一外键关系它们之间的键。

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    尝试删除

    public int? CountryID { get; set; }
    

    来自 UserProfile 所以它看起来像这样:

    public class UserProfile
    {
        [Key]
        public int UserID { get; set; }
    
        public virtual Country Country { get; set; }
    }
    
    public class Country
    {
        public Country()
        {
            Profiles = new HashSet<UserProfile>();
        }
    
        [Key]
        public int CountryID { get; set; }
    
    
        public ICollection<UserProfile> Profiles { get; set; }
    }
    

    另一件事:你有 ICollection&lt;Profile&gt; 而不是 ICollection&lt;UserProfile&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2021-08-20
      • 1970-01-01
      相关资源
      最近更新 更多