本人建议玩code frist的人多用用System.ComponentModel.DataAnnotations和System.ComponentModel.DataAnnotations.Schema这个里面的特性来写实体类现在进入正题,怎么打破原先外键的命名规则呢[Tabl ...
本人建议玩code frist的人多用用System.ComponentModel.DataAnnotations和System.ComponentModel.DataAnnotations.Schema这个里面的特性来写实体类
现在进入正题,怎么打破原先外键的命名规则呢
[Table("sys_UserInfo")] public partial class UserInfo { public UserInfo() { this.DelFlag = false; //this.R_UserInfo_Role = new R_UserInfo_Role(); } [Key]//主键 [Column("ID")] public int ID { get; set; } [Column("UName"), StringLength(20)] public string UName { get; set; } [Column("Pwd"), StringLength(20)] public string Pwd { get; set; } [Column("Phone"), StringLength(40)] public string Phone { get; set; } [Column("Mail"), StringLength(40)] 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; } [Column("R_RoleID")]//虽然在下面定义,但是可以重名 public int RoleID111 { get; set; } [ForeignKey("RoleID111")]//指定上面那个是外键的属性 public virtual Role Role { get; set; } }
原标题:EF中外键重命名,打破原先的约束规则
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。