日期:2014-05-20 浏览次数:20850 次
public class UserInfo { public int UserId { get; set; } public string UserName { get; set; } } public class Tasks { public int TaskId { get; set; } public int UserId { get; set; } public string TaskName { get; set; } }
modelBuilder.Entity<Tasks>().HasRequired(o => o.UserInfo).WithMany().HasForeignKey(f => f.UserId);
modelBuilder.Entity<UserInfo>().HasMany(o => o.Tasks).WithRequired(p => p.UserInfo).HasForeignKey(p => p.UserId);