我正在从 C# 中的代码查询 SQL 数据库中的 XML 列。我正在尝试获取唯一节点的列表。
在表中,有许多 ItemCodes(PK),每个都有一个对应ItemAttribute
的 XML 类型列。
假设 XML 文档中有 10 行和 3 个节点。我从下面使用的方法中得到 30 个结果。我只希望返回唯一的节点,但是因为每个节点中都有唯一的数据,所以我会根据节点中值的唯一性返回任意数量的结果。
var data = (from x in Ctx.ItemAttributeDatas
select x).ToList();
var xml = from x in data
where x.AttributeData.Descendants() != null
select x.AttributeData as XElement;
IEnumerable<XNode> nodes = (from x in xml.Nodes()
select x);
如何才能做到这一点?我尝试使用.Distinct()
但上述问题具有相同的结果。
另外,有没有一种更简洁的方法可以将数据以 xml 格式传输到节点?