简体   繁体   中英

one-to-One relationship, dropdownlist

I want a one-to-one relationship, between route and difficult level (simple, hard). I have these models:

public class Route
{

    [Key]
    public int routeID { get; set; }
    public string Name { get; set; }

    public int? UserProfileID { get; set; }
    public int? CountryID { get; set; }
    //public int? DifficultGradeID { get; set; }



    public virtual UserProfile userProfile { get; set; }
    public virtual Country country { get; set; }
    public virtual Difficult difficult { get; set; }
}

public class Difficult
{
    [Key, ForeignKey("Route")]
     public int routeID { get; set; }
     public string DifficultName { get; set; }

     public virtual Route route { get; set; }

}

but every time I do Update-Databse, I get this error:

The ForeignKeyAttribute on property 'routeID' on type 'ContosoUniversity.Models.Difficult' is not valid.
The navigation property 'Route' was not found on the dependent type 'ContosoUniversity.Models.Difficult'.
The Name value should be a valid navigation property name.

将Difficult类中的虚拟属性重命名为R oute而不是route。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM