J
Jon
Hi Guys,
I'm reading from an XML file :
<item>
<Product1>1</Product1>
<Product2>2</Product2>
<Qty>4</Qty>
</item>
<item>
<Product1>3</Product1>
<Product2>4</Product2>
<Qty>5</Qty>
</item>
<item>
<Product1>2</Product1>
<Product2>2</Product2>
<Qty>6</Qty>
</item>
<item>
<Product1>4</Product1>
<Product2>1</Product2>
<Qty>7</Qty>
</item>
I'm trying to get the total for each product id, currently I am using 2
seperate queries..
var p1 = from p in xmlfile.Elements("item")
group p by p.Product1 into g
select new
{
id = g.Key,
qty = g.Sum(o => o.Qty)
};
var p2 = from p in xmlfile.Elements("item")
group p by p.Product2 into g
select new
{
id = g.Key,
qty = g.Sum(o => o.Qty)
};
This doesn't total the product correctly because the id can be in either
product1 or product 2
What's the best way to combine the results?
Is there a query that I can use to combine on the fly? Or do I need to
iterate through and combine manually?
I'm reading from an XML file :
<item>
<Product1>1</Product1>
<Product2>2</Product2>
<Qty>4</Qty>
</item>
<item>
<Product1>3</Product1>
<Product2>4</Product2>
<Qty>5</Qty>
</item>
<item>
<Product1>2</Product1>
<Product2>2</Product2>
<Qty>6</Qty>
</item>
<item>
<Product1>4</Product1>
<Product2>1</Product2>
<Qty>7</Qty>
</item>
I'm trying to get the total for each product id, currently I am using 2
seperate queries..
var p1 = from p in xmlfile.Elements("item")
group p by p.Product1 into g
select new
{
id = g.Key,
qty = g.Sum(o => o.Qty)
};
var p2 = from p in xmlfile.Elements("item")
group p by p.Product2 into g
select new
{
id = g.Key,
qty = g.Sum(o => o.Qty)
};
This doesn't total the product correctly because the id can be in either
product1 or product 2
What's the best way to combine the results?
Is there a query that I can use to combine on the fly? Or do I need to
iterate through and combine manually?