我无法查看需要更正或添加到控制器的内容,以便将我的数据保存到数据库中。请参阅下面我到目前为止的内容。
创建方法
[HttpPost]
public ActionResult Create(Team model)
{
if (ModelState.IsValid)
{
new Team
{
Name = model.Name,
Division = model.Division,
Description = model.Description,
TeamContact = new TeamContact
{
EmailAddress = model.TeamContact.EmailAddress,
PhoneNumber = model.TeamContact.PhoneNumber,
TeamAddress = new TeamAddress
{
Box = model.TeamContact.TeamAddress.Box,
StreetName = model.TeamContact.TeamAddress.StreetName,
StreetNumber = model.TeamContact.TeamAddress.StreetNumber,
City = model.TeamContact.TeamAddress.City,
PostalCode = model.TeamContact.TeamAddress.PostalCode,
Province = model.TeamContact.TeamAddress.Province
}
}
};
_dataSource.Save();
}
return View(model);
表关系
-Team one-to-one TeamContact
-TeamContact one-to-on TeamAddress
IDataSource 接口
IQueryable<Team> Teams { get; }
IQueryable<TeamAddress> TeamAddresses { get; }
IQueryable<TeamContact> TeamContacts { get; }
void Save();
上下文类
public DbSet<Team> Teams { get; set; }
IQueryable<Team> IDataSource.Teams
{
get { return Teams; }
}
public DbSet<TeamAddress> TeamAddresses { get; set; }
IQueryable<TeamAddress> IDataSource.TeamAddresses
{
get { return TeamAddresses; }
}
public DbSet<TeamContact> TeamContacts { get; set; }
IQueryable<TeamContact> IDataSource.TeamContacts
{
get { return TeamContacts; }
}
public void Save()
{
SaveChanges();
}
将数据保存到数据库中我缺少什么?