I suggest playing code Frist people use System.ComponentModel.DataAnnotations and System.ComponentModel.DataAnnotations.Schema to write entity classes.
Now get to the point, how to break the original foreign key naming rules?
[Table ("Sys_userinfo")] public partial class UserInfo {public UserInfo () {this. Delflag = false; This. R_userinfo_role = new R_userinfo_role (); } [key]//primary key [Column ("ID")] public int ID {get; set;} [Column ("UName"), Stringlength ()] public string UName {get; set;} [Column ("Pwd"), Stringlength ()] public string Pwd {get; set;} [Column ("Phone"), Stringlength (+)] public string Phone {get; set;} [Column ("Mail"), Stringlength (+)] public string Mail {get; set;} [Column ("Subtime")] public System.DateTime subtime {get; set;} [Column ("Lastmodifiedon")] public System.DateTime Lastmodifiedon {get; set;} [Column ("Delflag")] public bool Delflag {get; set;} The [Column ("R_roleid")]//, although defined below, can have the same name as public int RoleID111 {get; set;} [ForeignKey ("RoleID111")]//specifies that the above is a foreign key attribute Public virtual role Role {get; set;} }
As I commented, when writing a foreign key, you can use the ForeignKey attribute to specify a foreign key attribute, and then rename the column name with column by the specified attribute. Do not need to write the mapping, and look at the time will be more intuitive, but also easy to maintain.
[Table ("Sys_role")] Public partial class role {public role () {this . Delflag = false; This. UserInfo = new hashset<userinfo> (); } [key]//primary Key [Column ("ID")] public int ID {get; set;} [Column ("RoleName"), Stringlength ()] public string RoleName {get; set;} [Column ("Delflag")] public bool Delflag {get; set;} [Column ("Subtime")] Public System.DateTime subtime {get; set;} [Column ("Userinfoid")] Public virtual icollection<userinfo> UserInfo {get; set;} }
Then a build in the database
EF foreign key renaming, breaking the original constraint rules