nhibernate-2

How can one delete an entity in nhibernate having only its id and type?

耗尽温柔 提交于 2019-11-30 01:01:30
问题 I am wondering how can one delete an entity having just its ID and type (as in mapping) using NHibernate 2.1? 回答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: note that this is subject to SQL injection - if possible use parametrized queries instead with SetParameter() session.Delete(string.Format("from {0} where id = {1}", type, id)); Edit: For Load,