c# - Remove entity in NHibernate only by primary key -
i'm trying implement repository method removing entities using primary key, because webapp aware of primary key when invoking "delete request" web page.
because of orm, option today entity database, , deleting it, gives me roundtrip.
i use hql delete, since want create generic delete method entities, won't fly unless use reflection find out field primary key (doable, doesn't feel correct).
or in nature of nhibernate need entity in order correctly handle cascades?
i tried approach, assumption not load entity unless explicitly necessary, haven't had time test yet. maybe can shed light on how handled?
var entity = session.load<t>( primarykey ); session.delete( entity );
edit: have tested , seems still full select on entity before deletion.
load
may return proxy object isn't guaranteed. mapping may contain cascade deletes force nhibernate load object database in order determine how delete object , graph.
i implement using load doing. objects nhibernate may not need select first. in cases does, that's [usually] trivial price pay using o/r mapper.
Comments
Post a Comment