We have implemented repository pattern using EF 4.x
The implementation revolves around one solid class which has generic methods as follows:

Code:
public virtual T Add(T obj)
{
...
...
}
Some entity classes implement an interface which contains a field CreatedOn. The above generic Add method checks if the entity class implements this interface. If the class, or its type T, does support the interface, the Add method will automatically update the CreatedOn field with the current datetime stamp.

This works well for ordinary objects. However trouble starts when I have one object within another object, both implementing the interface. I create the parent object, create the child object, associate the child with the parent (through property mapping the POCO-way), and call the Add method and pass the parent object to it.

In this case the Add method only works for the parent object, and not for the child object. This creates a problem where the CreatedOn field is not populated for the child object.

To take an example:

Code:
public class Order: ISpecialInterface
{
public virtual int Id { get; set; }
...
...
public virtual IList<OrderItem> Items { get; set; }
...
...
public virtual DateTime CreatedOn { get; set; }
...
}

public class OrderItem: ISpecialInterface
{
public virtual int Id { get; set; }
public virtual int OrderId { get; set; }
...
...
public virtual DateTime CreatedOn { get; set; }
...
}
I create the objects as follows:

Code:
public class Service
{

    public void CreateOrder()
    {

        Order o = new Order();
        o.Properties = Values;
        o.Items.Add(new OrderItem() { .... } );
        //Following statement uses dependency injection with MS Unity
        IOrderRepository orderRepository = ServiceFactory.GetInstance<IOrderRepository>();
        orderRepository.Add(o);
    }

}

When the Add method executes, it correctly assigns the CreatedOn field for the object o, which is of type Order. However it does not do so for the OrderItem object, which is a child of the Order object o.

How can I make it so that the Add method code will also execute for the OrderItem child object as well?