简体   繁体   English

NHibernate ISession.Delete

[英]NHibernate ISession.Delete

I know it´sa pretty simple question, but what happens when one calls ISession.Delete with a transient entity? 我知道这是一个非常简单的问题,但是当用一个瞬态实体调用ISession.Delete时会发生什么? I suspect that an exception is thrown, but could not find anything in the documentation. 我怀疑引发了异常,但在文档中找不到任何内容。

根据我的经验,不会抛出异常。

It will NOT throw any exception and it will NOT make any db call. 它不会抛出任何异常,也不会进行任何db调用。

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. CreateNormalSalesFlowActivies的第一个参数是NH Session,如果它是在实体附加到Session时提供的,并且默认情况下存储到db。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM