gpt4 book ai didi

c# - 如何将所有记录合并为 2 条记录并删除所有未合并的记录?

转载 作者:行者123 更新时间:2023-11-30 16:04:58 27 4
gpt4 key购买 nike

我使用以下代码合并(使用逗号)具有相同 Symptom_Type 的输入记录。现在的问题是我可以将记录合并并插入数据库,但是如何从“nPG_Chemical.NPG_Chemical_Symptoms”中删除那些未合并的记录?
enter image description here

var SymptomType = nPG_Chemical.NPG_Chemical_Symptoms.GroupBy(Type => Type.Symptom_Type);
foreach (var type in SymptomType)
{
var text = String.Join(", ", type.Select(x => x.Symptom_Text.ToString()).ToArray());
nPG_Chemical.NPG_Chemical_Symptoms.Add(new NPG_Chemical_Symptom
{
Symptom_Type = type.Key.ToString(),
Symptom_Text = text
});

db.SaveChanges();
}

最佳答案

我不确定我是否正确理解了您的要求。似乎你想要的只是

After you have combined records by Symptom_Type, and inserted them into database, you want to delete the original records.

如果这是你想要的,你可以这样做

db.YourTable
.RemoveRange(db.YourTable
.Where(x => !x.Symptom_Text.Contains(",")));

关于c# - 如何将所有记录合并为 2 条记录并删除所有未合并的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229762/

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