Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# entities.SaveChanges()未保存到数据库_C#_Entity Framework - Fatal编程技术网

C# entities.SaveChanges()未保存到数据库

C# entities.SaveChanges()未保存到数据库,c#,entity-framework,C#,Entity Framework,我正在尝试EF中的一个简单程序,将玩家从gridview添加到团队中。在savechanges部分之前,代码似乎一直有效。从其他帖子来看,我的代码有问题,但我看不出有什么问题 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { int v = Convert.ToInt32(GridView1.SelectedIndex); int pId = Convert.ToInt32(Gr

我正在尝试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();
}
protectedvoid GridView1\u SelectedIndexChanged(对象发送方,事件参数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();
刷新网格();
}

我遗漏了什么吗?或者您没有对数据库中的数据进行任何更改?您将一个实体抓取到chosenPlayer中,但不对其进行任何更改。您希望保存到数据库的
SaveChanges()
是什么?myTeam来自哪里?数据库是由EF模型生成的。团队成员ID名称团队myTeam=新团队()//在页面加载之前声明的想法是将chosenPlayer添加到myTeam。您的意思是您的更改未保存还是触发了一些异常?它们未保存。在调试模式下,在entities下,local旁边有一个X,显示消息“函数求值需要运行所有线程”。当我手动打开它时,它默认回到X。