Session.Delete overload

6 views
Skip to first unread message

epitka

unread,
Nov 21, 2009, 9:05:24 AM11/21/09
to nhusers
There is a Delete overload that accepts EntityName and Id. But was is
this EntityName? Is it name of the class or what? I am asking because
if I do Session.Delete("MetaProject", id) i get an error

NHibernate.MappingException: No persister for: MetaProject
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String
entityName)
at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName,
Object obj)
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete
(DeleteEvent event, ISet transientEntities)
at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete
(DeleteEvent event)
at NHibernate.Impl.SessionImpl.FireDelete(DeleteEvent event)
at NHibernate.Impl.SessionImpl.Delete(String entityName, Object obj)
at
dnnSphere.MetaTests.PersistenceSpecificationTests.MetaProjectTest.TearDown
() in MetaProjectTest.cs: line 127

epitka

unread,
Nov 21, 2009, 9:09:11 AM11/21/09
to nhusers
Ah, nevermind, it seems to require qualified name.

Fabio Maulo

unread,
Nov 21, 2009, 9:37:06 AM11/21/09
to nhu...@googlegroups.com
and it will load the entity
session.CreateQuery("delete from YourEntity y where y.Id = :pId)").SetInt32("pId", 5).ExecuteUpdate();
will NOT load the entity (and does not work with cascade)

2009/11/21 epitka <exptra...@yahoo.com>
--

You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=.





--
Fabio Maulo

epitka

unread,
Nov 21, 2009, 9:56:44 AM11/21/09
to nhusers
So, if I understand it correctly it is equivalent to

var o = Session.Get<MetaProject>(_metaProjectId);
Session.Delete(o);


On Nov 21, 8:37 am, Fabio Maulo <fabioma...@gmail.com> wrote:
> and it will load the entity
> session.CreateQuery("delete from YourEntity y where y.Id =
> :pId)").SetInt32("pId", 5).ExecuteUpdate();
> will NOT load the entity (and does not work with cascade)
>
> 2009/11/21 epitka <exptrade2...@yahoo.com>
>
>
>
>
>
> > Ah, nevermind, it seems to require qualified name.
>
> > On Nov 21, 8:05 am, epitka <exptrade2...@yahoo.com> wrote:
> > > There is a Delete overload that accepts EntityName and Id. But was is
> > > this EntityName? Is it name of the class or what? I am asking because
> > > if I do Session.Delete("MetaProject", id) i get an error
>
> > > NHibernate.MappingException: No persister for: MetaProject
> > > at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String
> > > entityName)
> > > at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName,
> > > Object obj)
> > > at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete
> > > (DeleteEvent event, ISet transientEntities)
> > > at NHibernate.Event.Default.DefaultDeleteEventListener.OnDelete
> > > (DeleteEvent event)
> > > at NHibernate.Impl.SessionImpl.FireDelete(DeleteEvent event)
> > > at NHibernate.Impl.SessionImpl.Delete(String entityName, Object obj)
> > > at
>
> > dnnSphere.MetaTests.PersistenceSpecificationTests.MetaProjectTest.TearDown
> > > () in MetaProjectTest.cs: line 127
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to nhu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com >
> > .

Fabio Maulo

unread,
Nov 21, 2009, 9:59:25 AM11/21/09
to nhu...@googlegroups.com
Yes.
the other option, perhaps even more easy and generic is
var e = session.Load<T>(id);
session.Delete(e);

2009/11/21 epitka <exptra...@yahoo.com>
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=.





--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages