如何使用ef core将xml文件中的数据保存到相关表中?

如何使用ef core将xml文件中的数据保存到相关表中?,xml,asp.net-core,.net-core,entity-framework-core,ef-core-3.1,Xml,Asp.net Core,.net Core,Entity Framework Core,Ef Core 3.1,我正在创建关联表,如下图所示。如何通过XML在相关表中保存数据 有关如何解决后端错误: public void SaveXMLFile(string path) { XDocument xDocument = XDocument.Load(path); List<Product> products = xDocument.Descendants("product").Select(p => new Product() {

我正在创建关联表,如下图所示。如何通过XML在相关表中保存数据


有关如何解决后端错误:

public void SaveXMLFile(string path)
{
    XDocument xDocument = XDocument.Load(path);
    List<Product> products = xDocument.Descendants("product").Select(p => new Product()
    {
        Productld = Convert.ToInt32(p.Element("ProductId").Value),
        AlisFiyati = long.Parse(p.Element("AlisFiyati").Value),
        Fiyat = long.Parse(p.Element("Fiyat").Value),
        KDVOrani = long.Parse(p.Element("KDVOrani").Value),
        IndirimliFiyatMi = bool.Parse(p.Element("IndirimliFiyatMi").Value),
        Indirim = long.Parse(p.Element("Indirim").Value),
        HavaleIndirimOrani = long.Parse(p.Element("HavaleIndirimOrani").Value),
        StokAdedi = long.Parse(p.Element("StokAdedi").Value),
        GarantiSuresi = long.Parse(p.Element("GarantiSuresi").Value),
        Resim1 = new Uri(p.Element("Resim1").Value),
        Resim2 = new Uri(p.Element("Resim2").Value),
        Resim3 = new Uri(p.Element("Resim3").Value),
        Resim4 = new Uri(p.Element("Resim4").Value),
        Resim5 = new Uri(p.Element("Resim5").Value),
        Resim6 = new Uri(p.Element("Resim6").Value),
        Puani = Convert.ToDouble(p.Element("Resim6").Value),
        ConnectProducts = new List<ConnectProduct>(){
            new ConnectProduct() {
                Features = new Features()
                {
                    Adet = Convert.ToInt32(p.Element("Adet"))
                }
            }
        }
    }).ToList();
}
public void SaveXMLFile(字符串路径)
{
XDocument XDocument=XDocument.Load(路径);
列出products=xDocument.substands(“产品”)。选择(p=>newproduct()
{
Productld=Convert.ToInt32(p.Element(“ProductId”).Value),
AlisFiyati=long.Parse(p.Element(“AlisFiyati”).Value),
Fiyat=long.Parse(p.Element(“Fiyat”).Value),
KDVOrani=long.Parse(p.Element(“KDVOrani”).Value),
IndirimliFiyatMi=bool.Parse(p.Element(“IndirimliFiyatMi”).Value),
Indirim=long.Parse(p.Element(“Indirim”).Value),
HavaleIndirimOrani=long.Parse(p.Element(“HavaleIndirimOrani”).Value),
StokAdedi=long.Parse(p.Element(“StokAdedi”).Value),
GarantiSuresi=long.Parse(p.Element(“GarantiSuresi”).Value),
Resim1=新Uri(p.Element(“Resim1”).Value),
Resim2=新Uri(p.Element(“Resim2”).Value),
Resim3=新Uri(p.Element(“Resim3”).值),
Resim4=新Uri(p.Element(“Resim4”).Value),
Resim5=新Uri(p.Element(“Resim5”).Value),
Resim6=新Uri(p.Element(“Resim6”).Value),
Puani=转换为双值(p.Element(“Resim6”).值),
ConnectProducts=新列表(){
新产品(){
功能=新功能()
{
Adet=转换为32(p.Element(“Adet”))
}
}
}
}).ToList();
}

我尝试执行此操作,但出现了以下错误,我也不知道如何执行。您的代码出错是因为您没有转换为正确的类型。但不确定当所有属性类型都匹配时,它是否能够正确读取文件,因为不确定您获得的元素是否正确。因此,请共享您的xml文件。此外,请分享代码而不是图片!