AfterExecFilter / InsertFilter

Hi,
I need to run a script on after insert and use the inserted id.
InsertFilter is running before. not helping me.
AfterExecFilter does not contain the created entity inside… (like InsertFilter does).

What is the best way to run a script after a specific entity was inserted to the database.
Thanks

Call a helper method that inserts and does what else you need.

@mythz i don’t think you got me.
I meed to use the object/entity that was just inserted.
Is it possible to get the object that was just inserted?
I just have the insert statement string… which is not helping…
Thanks

There’s no generic filter that generically lets you access the last inserted id, you’ll need to call the Insert method yourself, the OrmLite docs shows how to fetch the Insert Id:

Save Methods

Save and SaveAll will Insert if no record with Id exists, otherwise it Updates.

Save will populate any [AutoIncrement] or [AutoId] Primary Keys, e.g:

db.Save(item);
item.Id // RDBMS populated Auto Id 

Alternatively you can also manually Select and Retrieve the Inserted RDBMS Auto Id in a single query with Insert APIs by specifying selectIdentity:true:

item.Id = db.Insert(item, selectIdentity:true);

So, In my class I have this:

    public class PropsEntity
    {
        public string Name {get;set;}
        public string Type {get;set;}

        [Reference]
        public List<ProfileImageEntity> ProfileImages { get; set; } = new List<ProfileImageEntity>();
}

When I Save a new PropsEntity with its ProfileImages collection, I cant really trigger the postInsert event and know the type + id that was saved?

This PropsEntity has around 15 Lists inside… in this case, what are you suggesting to do?
because saving each manually is a headake.

Thanks

OrmLite Docs on Saving POCO References.

When you save your POCO References entity with References, e.g:

db.Save(customer, references:true);

It automatically populates the child references keys.

Thank. but this I already know. This is not the question.
I’m looking for a way to trigger the ProfileImages post insert after running db.Save(propsEntity, references:true);

I know ormlite is far away from NHibernate, but there is some similarity, and this is the best way for me to demonstrate better what I’m looking for.
In NHibernate you have:

public class ProfileImageEvent : DefaultPostLoadEventListener{
   public virtual void OnPostInsert(PostInsertEvent @event){
      //@event.Entity.Id
      //@event.Entity.GetType()
   }
}

in this case the @event variable has all I need.
So when I save PropsEntity and inside there is a new item in the collection ProfileImages the post insert event will be triggered.

You can say that

OrmLiteConfig.InsertFilter = (dbCmd, row) => {}

is perfect, but im looking a way to have the same thing for post insert

for some reason I can’t express my need.
Thank you for your patience.

I’ve been trying to say there is no such callback or event.

Call a helper that calls your model after it’s been inserted, e.g:

db.Save(customer, references:true);
customer.ProfileImages.ForEach(x => x.OnPostInsert());

Thank you.
Are you concidering this feature?
Is this a heavy one?
Thanks

It’s never been requested so unlikely to be considered, you can submit feature requests on UserVoice to measure demand, please include a clear use-case explaining why the feature is useful.

Thanks. I will.
Why have you chosen to implement a pre-event (InsertFilter) and not a post-event? is it something specific?
I think it exists in every ORM I have seen…
Thanks anyway for your time!

Being able to add pre-insert validation logic is useful, a post insert callback isn’t and I don’t know of a single .NET Micro ORM that provides it. As there’s no demand for the feature I’d stick to a non ORM-specific solution and run custom logic after the entities have been saved.