如何将Linq查询结果转换为XML? [英] How do you transform a Linq query result to XML?

查看:48
本文介绍了如何将Linq查询结果转换为XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linq to XML领域的新手...

Newbie in the Linq to XML arena...

我有一个带有结果的Linq查询,我想将这些结果转换为XML.我猜肯定有一种相对简单的方法可以做到,但是我找不到它...

I have a Linq query with results, and I'd like to transform those results into XML. I'm guessing there must be a relatively easy way to do it, but I can't find it...

谢谢!

推荐答案

一个示例.你应该明白这个主意.

An Example. You should get the idea.

XElement xml = new XElement("companies",
            from company in db.CustomerCompanies
            orderby company.CompanyName
            select new XElement("company",
                new XAttribute("CompanyId", company.CompanyId),
                new XElement("CompanyName", company.CompanyName),
                new XElement("SapNumber", company.SapNumber),
                new XElement("RootCompanyId", company.RootCompanyId),
                new XElement("ParentCompanyId", company.ParentCompanyId)
                )
            );

这篇关于如何将Linq查询结果转换为XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆