Delete all rows from table in NHibernate
I have an application using Fluent NHibernate and NHibernate, I have a generic DAO class, in this class I have generic methods for persisting data, but I want to create a generic method to delete all records from one table. At this point, I have this method:
Public Sub ClearTable(ByVal sTable As String)
Using session = SessaoNHibernate.OpenSession()
Using transaction = session.BeginTransaction()
Try
session.CreateSQLQuery("delete from " & sTable).ExecuteUpdate()
transaction.Commit()
session.Flush()
Catch ex As Exception
transaction.Rollback()
End Try
End Using
End Using
End Sub
I have a generic class, so I want to create a method that shouldn't pass the table name. Because the generic class knows its type.
+3
source to share