How to modify entities in UOW before Insert

Posts   
 
    
Philip
User
Posts: 17
Joined: 01-May-2009
# Posted on: 19-May-2009 15:36:25   

Hi there,

I am using: Version: LLBLGen Pro 2.6 Final SD.Presets.SelfServicing.General2008 with merged AdditionalTemplates.LinqADODS

I have tried a number of things, but haven't yet found the right way to do this. I am trying to calculate a field in all entities (of a specific type) before they are committed to persistent storage. I tested my logic by just modifying the SaveChanges() method in LinqMetaData.adods.cs and it worked fine. Obviously, I don't want to have my code live there as that is generated code.

I tried to override the method, but it's not virtual. I also tried to change the template to make it virtual, but then that breaks some other code in LinqMetaData.adods that relies on reflection (MethodInfo.GetType()).

So, at this point, I'm looking for a bit of guidance. What would be the best way of intercepting and modifying entities before _uow.commit() in LinqMetaData.adods?

Here's what I'm trying to accomplish, but not within generated code.

public void SaveChanges()
{
    if (_transactionToUse == null)
    {
        _uow.ConstructSaveProcessQueues();
        foreach (var s in _uow.GetInsertQueue().Where(s => s.Entity is StudyEntity))
        {
            var study = (StudyEntity) s.Entity;
            study.Itn = "Set this to something.";
        }
        _uow.Commit(new Transaction(System.Data.IsolationLevel.ReadCommitted, "UOW"), true);
    }
    else
    {
        _uow.Commit(_transactionToUse, true);
    }
}

Thanks very much for your help. Philip

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-May-2009 20:48:58   

Have you looked at overriding/incerpeting the save methods/events on the individual entities ? Is there a particular reason why it has to be done in the UOW...?

Matt

Philip
User
Posts: 17
Joined: 01-May-2009
# Posted on: 19-May-2009 23:15:32   

Matt,

Thanks. That is what I needed. I just missed it somehow.

Best, Philip