How to delete an object by using PK in nhibernate?

后端 未结 5 1230

How do I delete an object without fetching it from the db first?

In another ORM, I can do this:

session.Delete(1); // 1 = PK
5条回答
  •  难免孤独
    2021-02-02 17:10

    Try this:

    var user = session.Load(1);
    session.Delete(user);
    

    Load will create a proxy for the User object with the identifier set. I'm not sure if Delete will load the object from the database before deleting it and I'm unable to test it at the moment.

提交回复
热议问题