linq 不会迭代列表
我编写了以下代码,
List<Pupils> pupils = PupilsDAO.SelectDAO();
XElement dtpupil = new XElement("DtDatas",
from xlist in pupils
orderby xlist.Id
select new XElement("DtData",
new XElement("ref", xlist.Id),
new XElement("forename", xlist.Forename),
new XElement("surname", xlist.Surname)
)
);
而不是为列表中的每个元素获取不同的 XML 对象,我确实为列表中的每个项目获取了输出,但它们都是相同的,而不是实际迭代,因此只需加载比如说...
<DtDatas>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
</DtDatas>
有人有什么想法吗?我是否打算为列表添加迭代?
I've written the following code
List<Pupils> pupils = PupilsDAO.SelectDAO();
XElement dtpupil = new XElement("DtDatas",
from xlist in pupils
orderby xlist.Id
select new XElement("DtData",
new XElement("ref", xlist.Id),
new XElement("forename", xlist.Forename),
new XElement("surname", xlist.Surname)
)
);
rather than getting a different XML object for each element in the list, I do get an output for every item in the list, but they're all the same rather than actually iterating through the, so just loads of say...
<DtDatas>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
<DtData>
<ref>01</ref>
<forename>joe</forename>
<surname>bloggs</surname>
</DtData>
</DtDatas>
Does anyone have any ideas? Am I meant to add an iteration for the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的代码很好。这表明您列表中的数据不正确。可能的选项:
如果您可以发布
Pupils
类和SelectDAO
方法,我们应该能够提供更多帮助。The code you've presented is fine. That suggests that the data in your list is incorrect. Possible options:
If you can post the
Pupils
class and theSelectDAO
method, we should be able to help more.