Save() to InsertEntity/UpdateEntity

Posts   
 
    
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 22-Sep-2008 09:28:12   

Hey.

I am using: - SQL Server 2005 - VS 2008 - .Net 3.5 - LLBLGen 2.6.8.819 (Self Servicing - Two classes)

I had a whole bunch of logic on the Save method of an Entity, e.g ResultEntity, which worked fine.

I then noticed that the overridden Save method of the ResultEntity is not called when the entity is recursively saved from another Entity. i.e:


SampleEntity s = new SampleEntity();
s.Number = 1337;

ResultEntity r1 = new ResultEntity();
r1.Value = 1337;
s.Result.Add(r1);

ResultEntity r2 = new ResultEntity();
r2.Value = 1337;
s.Result.Add(r2);

s.Save(true);

So I decided to spit the code in the Save method of the ResultEntity into the InsertEntity and UpdateEntity methods (which i guess should have been done from the start).

We are looking at the Save() method of the ResultEntity.


public override bool Save(IPredicate updateRestriction, bool recurse)
{
    if (Comment == null || CommentId == Guid.Empty)
    {
        Comment = new CommentEntity();
        Comment.Description = "Description";
    }

    return base.Save(updateRestriction, recurse);
}

Which now is in the InsertEntity method of the ResultEntity like so:


protected override bool InsertEntity()
{
    if (Comment == null || CommentId == Guid.Empty)
    {
        Comment = new CommentEntity();
        Comment.Description = "Description";
    }

    return base.InsertEntity();
}

But the CommentEntity is now not saved anymore?

Do I explicitly have to call the Save() on the Comment after setting the "Description" in the InsertEntity? And if so, will it still be a part of the internal transaction that the Sample/Result entities use in the first code snippet I pasted.

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Sep-2008 10:25:07   
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 22-Sep-2008 10:35:30   

Ah, so sorry about that.

I didn't search through general forum, just generated code and the bugs and issues one. simple_smile

I will read through it thanks.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Sep-2008 10:47:58   

Ah, so sorry about that.

No need for that. Hope the other thread answers your question.