The problem is I'm trying to find a single method to save an entity, be it a new entity or an already loaded entity. Most all code samples separate Add and Save methods which goes against so many other current designs of having a single Save() method.

Let me state I've read the other posts. I've looked at the team blog on repository pattern as well which has a single AddObject() method that I can't seem to find by assuming it just is an Add(object). 

If we load an object and save it, the context knows about it. 
A new object we MUST add. 
If we add an existing object - it will send it over as an insert.

I want one save procedure here. A user shouldn't have to know to call Add or Update, a Save() should suffice. With that said, whats the best route here for a single save solution that covers in the same method (only the save, not the load):
1. loading an entity, saving back to the db.
2. Creating a new entity, saving it to the db.
So I'm looking for an implementation that in all cases can just be

```
ICustomerRepository.Save(Customer customer)
```

What solution would you be using that works?

The following code in a Save(entity) method seems to work for me

```

//If the primary key is empty, its a new record
if (order.OrderId == 0)
{
   _context.Orders.Add(order);
}

if (_context.Entry(order).State == System.Data.EntityState.Detached)
{
   //Need to set modified so any detached entities are updated otherwise they won't be sent across to the db. Since it would've been outside the context, change tracking wouldn't have occurred anyways so we have no idea about its state - save it!
   _context.Orders.Attach(order);
   _context.Entry(order).State = System.Data.EntityState.Modified;
}

```

The issue here though is with a Generic Repository implementation there is no clear way here without querying what the key is and checking its value then via reflection which isn't clean.