Hello
I'm not 100% sure that I've implemented my Repository and UnitOfWork patterns correctly, but then I can't see how else this will work.
For example, I have two objects, Apple and Orange.
Apple is joined to Orange via an OrangeID like so:
public class Apple
{
public int OrangeID { get; set; }
}
I want to create a new Apple and a new Orange, and I want to set the ID link up appropriately. But I have a problem. I won't know the OrangeID until I have saved the Orange to the database.
So this means I will have the following:
var unitOfWork = new UnitOfWork();
Orange newOrange = new Orange();
OrangeRepository.Insert(newOrange);
unitOfWork.Commit();
//newOrange will have been updated with the actual ID
Apple newApple = new Apple(newOrange.ID);
etc...
This is not an atomic operation, unless I have a transaction that sits outside the above. But I thought that was what UnitOfWork was supposed to handle? Or should my UnitOfWork.Commit() assign the appropriate values when it's writing to the database?
Any help/tips would be appreciated, thanks Duncan