gpt4 book ai didi

c# - Linq 插入 : The column name ' ' is specified more than once in the SET clause or column list of an INSERT

转载 作者:行者123 更新时间:2023-11-30 15:54:40 24 4
gpt4 key购买 nike

我正在使用 EF,但无法将数据插入表中。

问题类看起来像这样

[Table("QUESTION")]    
public class QUESTION
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }

public int q_id { get; set; }

public string questname { get; set; }

public string optionname { get; set; }
}

插入方法

public string Save(QUESTION newquestion)
{
try
{
using (dbcontextdata Context = new dbcontextdata())
{
QUESTION dbquest = new QUESTION();
dbquest.id = newquestion.id;
dbquest.q_id = newquestion.q_id;
dbquest.questname = newquestion.questname;
dbquest.optionname = newquestion.optionname;
Context.QUESTIONs.Add(dbquest);
Context.SaveChanges();
}
}
catch (Exception e)
{
return e.Message;
}
return "OK";
}

当我发布数据时,它在 SaveChanges() 中显示错误

The column name 'q_id' is specified more than once in the SET clause or column list of an INSERT. A column cannot be assigned more than one value in the same clause. Modify the clause to make sure that a column is updated only once. If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.

这里q_id是FK,帮帮我。

最佳答案

您需要将 q_id 显式定义为外键,如下所示。

 [ForeignKey("MyForeignTable")]
public int q_id { get; set; }

关于c# - Linq 插入 : The column name ' ' is specified more than once in the SET clause or column list of an INSERT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49940413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com