Get the App
SLTechnology News&Howtos  ›  Development  › 

Can the XElement of LINQ to SQL Table and LINQ to XML be join?

Shulou Source: shulou.com Published: 2022-06-02 08:59:37 10月01日 Update

This article mainly introduces whether the XElement of LINQ to SQL Table and LINQ to XML can be join up, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

Writing about Linq To SQL, as a result of exploring the core concepts of LINQ, a thought popped up in my mind, "can I combine LINQ to SQL Table with LINQ to XML's XElement join?"

In theory, this is feasible in LINQ's design concept.

Static void TestCrossLinq ()

{

NORTHWND db = new NORTHWND ("Data Source=.\\ SQLEXPRESS"

Initial Catalog=NORTHWND;Integrated Security=True ")

XDocument doc = XDocument.Load ("XMLFile1.xml")

Var p = from S1 in doc.Elements ("tables"). Elements ("table").

Descendants ("row")

Join S2 in db.Customers on s1.Element ("CUSTOMER_ID").

Value equals s2.CustomerID

Where s1.Parent.Attribute ("name")! = null &

S1.Parent.Attribute ("name") .Value = "Orders"

Select new XElement ("Order", s1.Nodes ()

New XElement ("CompanyName", s2.CompanyName))

Foreach (var item in p)

{

Foreach (var item3 in item.Elements ())

{

Console.WriteLine ("{0}: {1}", item3.Name, item3.Value)

Console.WriteLine ("-")

}

}

Console.ReadLine ()

}

This program reads the Order information from XML, uses the data in its CUSTOMER_ID Element to communicate with Linq To SQL Table: Customers join, takes out the CompanyName field and puts it into the result set.

Thank you for reading this article carefully. I hope the article "whether the XElement of LINQ to SQL Table and LINQ to XML can be join up" shared by the editor will be helpful to you. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles concepts information feasibility value interest at the same time ideas more friends core theory knowledge programs results editing industry materials information channels this is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Microsoft MySQL NVidia