1:(0or1)
1508 ワード
public class User { public int ID { get; set; }
public string UserName { get; set; }
public string Passwd { get; set; }
public virtual UserInfo UserInfo { get; set; }
}
public class UserInfo { public int ID { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public virtual User User { get; set; }
public int UserID { get; set; }
}
public string UserName { get; set; }
public string Passwd { get; set; }
public virtual UserInfo UserInfo { get; set; }
}
public class UserInfo { public int ID { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public virtual User User { get; set; }
public int UserID { get; set; }
}
//
modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<User>().HasKey(u => u.ID);
modelBuilder.Entity<UserInfo>().ToTable("UserInfos");
modelBuilder.Entity<UserInfo>().HasKey(b => b.ID);
//// “ , ”
modelBuilder.Entity<User>().HasOptional(b => b.UserInfo)
.WithRequired(x => x.User);