Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PLZ HELP!!!Not able to Delete the records from DB using NHibernate

PLZ HELP!!!Not able to Delete the records from DB using NHibernate

Scheduled Pinned Locked Moved C#
helpdatabasetutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Puneet Bhatnagar
    wrote on last edited by
    #1

    Hi, I am using NHibernate to persist my objects. To delete an object from DB I have written the below code : I have checked my DB too and it has records. public void Delete(T item) { try { using (ISession session = factory.OpenSession()) { using (session.BeginTransaction()) { session.Delete(item); session.Transaction.Commit(); //Code is breaking here. } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); System.Windows.Forms.MessageBox.Show(e.StackTrace); } } The code is breaking at line session.transaction.commit(); with following error message "Unexpected row count: 0; expected: 1" Please let me know how to fix this. Thanks in Advance Regards Puneet

    S 1 Reply Last reply
    0
    • P Puneet Bhatnagar

      Hi, I am using NHibernate to persist my objects. To delete an object from DB I have written the below code : I have checked my DB too and it has records. public void Delete(T item) { try { using (ISession session = factory.OpenSession()) { using (session.BeginTransaction()) { session.Delete(item); session.Transaction.Commit(); //Code is breaking here. } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); System.Windows.Forms.MessageBox.Show(e.StackTrace); } } The code is breaking at line session.transaction.commit(); with following error message "Unexpected row count: 0; expected: 1" Please let me know how to fix this. Thanks in Advance Regards Puneet

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, long time that I did something with hibernate, but I think the problem is, that the item you want to delete is associated with another session. Try to refresh the item with the new session before you delete it (this is not the best way to do this, it is just a quick-and-dirty solution).

      ...
      session.Refresh(item);
      session.Delete(item);
      ...

      Please let me know if this fixed your problem. Regards Sebastian

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups