gpt4 book ai didi

c# - 将 IEnumerable 保存到数据库中

转载 作者:太空宇宙 更新时间:2023-11-03 21:13:34 24 4
gpt4 key购买 nike

我有模型:它的数据来 self 解析它的某个站点。

public class Race
{
[Key]
public int Id;
public string Cars;
public string Place;
public string Pilot;
}

var compare = Doc.DocumentNode
.SelectNodes(path)
.Select(s => new Race()
{
Cars =s.SelectNodes("./div[1]//text()").Single().InnerText,
}
);
using (_context) // how can I do this?
{
_context.Race.Add(compare);
_context.SaveChanges();
}

Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<Race>' to 'Race'

最佳答案

您应该使用 AddRange 而不是 Add

using (_context)     //  how can I do this?
{
_context.Race.AddRange(compare);
_context.SaveChanges();
}

关于c# - 将 IEnumerable 保存到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36038978/

24 4 0
文章推荐: c# - 绑定(bind)到绑定(bind)元素?
文章推荐: javascript - CSS/Javascript 下拉菜单问题
文章推荐: jquery -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com