sanosdole
sanosdole

Reputation: 2489

NHibernate ISession.Delete

I know it´s a pretty simple question, but what happens when one calls ISession.Delete with a transient entity? I suspect that an exception is thrown, but could not find anything in the documentation.

Upvotes: 0

Views: 687

Answers (2)

isuruceanu
isuruceanu

Reputation: 1157

It will NOT throw any exception and it will NOT make any db call.

here is the unit test which pass:

    [Test]
    public void TestDeletionOnTransientObject()
    {
        NormalSalesFlowActivity normalSalesFlowActivity =
            Factories.SalesFlowActivityFactory.CreateNormalSalesFlowActivities(null, 
            opt => opt.NoOfEntities(1)).First();

        Assert.That(normalSalesFlowActivity.Id, Is.EqualTo(0));

        Session.Delete(normalSalesFlowActivity);
    }

First parameter of CreateNormalSalesFlowActivies is the NH Session, if it is supplied when entity is attached to Session and by default is stored to db.

Regards

Upvotes: 1

jasonp
jasonp

Reputation: 410

Based on my experience, an exception will NOT be thrown.

Upvotes: 1

Related Questions