asp.net-mvc - 如何在 ASP.NET MVC 中更新相关数据?
问题描述
我在 ASP.NET MVC 中有两个具有多对多关系的表,如下所示:
public class Course
{
[Key]
public int Id { get; set; }
public string Title { get; set; }
public int Capacity { get; set; }
public virtual ICollection<DayTime> DayTimes{ set; get; }
}
public class DayTime
{
public int Id { get; set; }
public WeekDaysEn Day { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public virtual ICollection<Course> Course{ get; set; }
}
当记录Course
是这样的:
{
id = 1,
title = 'test',
capacity = 20,
{
DayTimes = { id = 2, Day = 0, StartTime = '10:00', endTime = '12:00' }
}
}
当我尝试更新它并定义如下数据时:
{id=1,title='test',capacity=20,
{DayTimes={id=2,Day=0,StartTime='10:00',endTime='12:00'},
{id=2,Day=0,StartTime='12:00',endTime='14:00'}
}
新DayTime
记录未在CourseDayTime
表中更新