entities.SaveChanges()未保存到db

时间:2014-05-17 00:38:43

标签: c# entity-framework

我在EF中尝试一个简单的程序,将一个玩家从gridview添加到团队中。代码似乎一直有效,直到savechanges部分。从其他帖子来看,我的代码存在问题,但我看不清楚。

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    int v = Convert.ToInt32(GridView1.SelectedIndex);
    int pId = Convert.ToInt32(GridView1.DataKeys[v].Value);
    chosenPlayer = entities.Players.Find(pId);
    int noPlayers = myTeam.Players.Count();

    if (noPlayers < 5)
    {
        myTeam.Players.Add(chosenPlayer);
    }
    entities.SaveChanges();
    RefreshGrid();
}

0 个答案:

没有答案