Dear ladies and sirs.
I am wondering how can one delete an entity having just its ID and type (as in mapping) using NHibernate?
Thanks.
P.S. I use NHibernate 2.1
Dear ladies and sirs.
I am wondering how can one delete an entity having just its ID and type (as in mapping) using NHibernate?
Thanks.
P.S. I use NHibernate 2.1
If you are using lazy loading, Load only creates a proxy.
session.Delete(session.Load(type, id));
With NH 2.1 you can use HQL. Not sure how it actually looks like, but something like this:
session.Delete(string.Format("from {0} where id = {1}", type, id));
Edit:
For Load, you don't need to know the name of the Id column.
If you need to know it, you can get it by the NH metadata:
sessionFactory.GetClassMetadata(type).IdentifierPropertyName