【发布时间】:2017-02-28 21:02:32
【问题描述】:
我正在创建身份用户和游戏表之间的联结表。此表称为 UserGame,具有两个外键(UserID、GameID)和一个用于存储分数的附加字段。
public class UserGame
{
[Key]
public string ApplicationUserID { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public int GameID { get; set; }
public virtual Game Game { get; set; }
public int Score { get; set; }
}
我的困惑在于创建新的 UserGame 记录。我将如何去做,我的方法是否正确?
更新(有效):
[HttpPost]
public ActionResult SubmitScore(int gameID, int score)
{
var playerRecord = new UserGame();
playerRecord.ApplicationUserID = User.Identity.GetUserId();
playerRecord.GameID = gameID;
playerRecord.Score = score;
return Json(new { success = true });
}
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework asp.net-identity junction-table