Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.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# 使用实体框架插入多行时出错_C#_Entity Framework - Fatal编程技术网

C# 使用实体框架插入多行时出错

C# 使用实体框架插入多行时出错,c#,entity-framework,C#,Entity Framework,尝试在此关系上插入多行时出现此错误 检测到冲突的更改 尝试插入具有相同密钥的多个实体时可能会发生这种情况 代码如下: foreach (var newValue in values) { Container.EnviromentValues.AddObject(new EnviromentValue() { key = newValue.Key, value = newValue.Value, env_id = some_in

尝试在此关系上插入多行时出现此错误

检测到冲突的更改

尝试插入具有相同密钥的多个实体时可能会发生这种情况

代码如下:

foreach (var newValue in values) 
{
    Container.EnviromentValues.AddObject(new EnviromentValue() 
    { 
        key = newValue.Key,
        value = newValue.Value,
        env_id = some_int
    });
}

return Container.SaveChanges() > 0;

EnvironmentValues
表的主键是什么?它是
env_id
?主键是一个名为“id”的列,也是标识。