我面临下一个问题。我有一个带有模型的数据仓库
public class GameResult
{
public int GameResultId { get; set; }
public virtual Competition Competition { get; set; }
public virtual CustomDate DateGame { get; set; }
public virtual Contender ContenderFirst { get; set; }
public virtual Contender ContenderSecond { get; set; }
public virtual Location Location { get; set; }
}
public class Competition
{
[Key]
public int CompetitionId { get; set; }
public string Name { get; set; }
//Lazy loading
public virtual KindSport KindSport { get; set; }
}
类似的东西我为事实表生成了一些数据GameResult
gameResult.Location = location;
gameResult.Competition = competition;
gameResult.ContenderFirst = firstContender;
gameResult.ContenderSecond = secondContender;
public void saveGameResult(GameResult gameResult)
{
using (var db = new GameContext())
{
db.GameResults.Add(gameResult);
db.SaveChanges();
}
}
但是,当我尝试保存数据时,我发现我并没有将实体保存在事实表中,它们也将级联保存在子表中作为Location, Contender
.
我怎样才能解决我的问题?