Deserialize, Copy and Merge Orders from XML to C# Here's the flow,


Load XML file
Deserialize to list in c#
Map xml object to c# list
Merge orders but increment order's product count

public Order[] Load(string path)
{
    var element = XElement.Load(path);
    var orders = new List&lt;XElement&gt;();
    orders = element.Elements();

    var _orders = new List&lt;Order&gt;();
    var _alreadyAddedOrders = new List&lt;string&gt;();
    foreach (var order in orders)
    {
        var orderTemp = new Order();
        orderTemp.OrderDate = Convert.ToInt32(order.Attribute("date").ToString());
        orderTemp.Id = Convert.ToInt32(order.Attribute("id").ToString());
        orderTemp.CategoryId = Convert.ToInt32(order.Attribute("categoryId").ToString());
        orderTemp.ProductCount = Convert.ToInt32(order.Attribute("productCount").ToString());

        foreach (var secondOrder in _orders)
        {
            var orderMatches = (orderTemp.OrderDate == secondOrder.OrderDate &amp;&amp; 
                                orderTemp.Id == secondOrder.Id &amp;&amp; 
                                orderTemp.CategoryId == secondOrder.CategoryId);
            if (orderMatches)
            {
                orderTemp.ProductCount += secondOrder.ProductCount;
                _alreadyAddedOrders.Add(secondOrder.OrderDate.ToString() + secondOrder.Id.ToString() + secondOrder.CategoryId.ToString());
            }
        }

        if(!_alreadyAddedOrders.Contains(orderTemp.OrderDate.ToString() + orderTemp.Id.ToString() + orderTemp.CategoryId.ToString()))
            _orders.Add(orderTemp);
    }

    return _orders.ToArray();
}

public class Order
{
    public int Id;
    public int CategoryId;
    public int OrderDate;
    public int ProductCount;
}



and XML is like this, more then 20,000 rows,

&lt;orders&gt;
    &lt;order date='2000-04-20' Id='1' categoryId='100' productCount='3' /&gt;
    &lt;order date='2000-06-21' Id='2' categoryId='101' productCount='14' /&gt;
&lt;/orders&gt;


Note : Order ID is not unique, date + id + category, is unique altogether
Naming
var orders = new List&lt;XElement&gt;();
var _orders = new List&lt;Order&gt;();

First, according to the C# naming convention, you should never have underscores in your variable names declared inside methods. Second, this is pretty confusing.
How about :
var xmlOrders = new List&lt;XElement&gt;();
var convertedOrders = new List&lt;Order&gt;();

It's a weird (and probably controversial) thing to say, but naming has to be one of the hardest thing to do when it comes to programming. You want your name to be so clear that anyone reading your code would be able to understand it quickly. So names need to be clear and exact.
For example : secondOrder isn't a second order, so it's confusing.
What is it, how should it be named? Well it seems like this order is an alreadyAddedOrder. You might want to find another name, but it should give the same &quot;vibe&quot;.
C# things

You can use the object initializer :
var orderTemp = new Order();
orderTemp.OrderDate = Convert.ToInt32(order.Attribute(&quot;date&quot;).ToString());
orderTemp.Id = Convert.ToInt32(order.Attribute(&quot;id&quot;).ToString());
orderTemp.CategoryId = Convert.ToInt32(order.Attribute(&quot;categoryId&quot;).ToString());
orderTemp.ProductCount = Convert.ToInt32(order.Attribute(&quot;productCount&quot;).ToString());


becomes :
var orderTemp = new Order
{
    OrderDate = Convert.ToInt32(order.Attribute(&quot;date&quot;).ToString()),
    Convert.ToInt32(order.Attribute(&quot;id&quot;).ToString()),
    //etc..
};

It's simply shorter and clearer, but it is compiled the same way as your previous code.


Note : Order ID is not unique, date + id + category, is unique altogether


We've got a great case of override Equals.
As it is right now, the responsibility of deciding if two orders are equal is stored (as code) in your Load method. Is this fine? I don't think so!
An Order should be able to tell if it's equal to another Order`.
public class Order
{
    public int Id;
    public int CategoryId;
    public int OrderDate;
    public int ProductCount;

    public override Equals(object obj)
    {
       //etc.
    }
}

I recommend you read a little bit on how to correctly implement the Equals override as you'll also need to override the GetHashCode method.

Don't use Convert.ToInt32 when you have a string that should be an int. Use int.Parse. reference

Also, override ToString to replace orderTemp.OrderDate.ToString() + orderTemp.Id.ToString() + orderTemp.CategoryId.ToString().


Encapsulation
public class Order
{
    public int Id;
    public int CategoryId;
    public int OrderDate;
    public int ProductCount;
}

Now, you might not feel it's necessary to implement this as it's a pretty &quot;defensive programming&quot; thing, but I feel it's important to talk about it. If I look at this class from a business point of view, it means that if I pass an order, I should be able to modify the said order afterwards. But when an order is passed, should I be able to modify, say, the OrderDate? Not really. There's also an important point that once you override the GetHashCode method, you should consider making your object &quot;read only&quot;, so that it doesn't mess with the hashes.
Order becomes :
public class Order
{
    public Order(int id, int categoryId, int orderDate, int productCount)
    { 
        //etc.
    }

    public int Id { get; }
    public int CategoryId { get; }
    public int OrderDate { get; }
    public int ProductCount { get; }

    //Equals and GetHashCode override.
}

General points

Don't use _alreadyAddedOrders to keep string. You're looking for orders, this list should contain orders.

Why is OrderDate an int? If it's stored as milliseconds, it should be a long, otherwise I don't see how you can parse an int to a meaningful date.