Namespaces

Types

Type ISession

Namespace NHibernate

Interfaces IDisposable

Methods

Properties

Public instance methods

ITransaction BeginTransaction(IsolationLevel isolationLevel)

Begin a transaction with the specified isolationLevel
Parameters
return ITransaction A transaction instance having the specified isolation level
IsolationLevel isolationLevel Isolation level for the new transaction

ITransaction BeginTransaction()

Begin a unit of work and return the associated ITransaction object.
If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the context of the existing underlying transaction. The class of the returned ITransaction object is determined by the property hibernate.transaction_factory
Parameters
return ITransaction A transaction instance

void CancelQuery()

Cancel execution of the current query.
May be called from one thread to stop execution of a query in another thread. Use with care!

void Clear()

Completely clear the session. Evict all loaded instances and cancel all pending saves, updates and deletions. Do not close open enumerables or instances of ScrollableResults .

IDbConnection Close()

End the ISession by disconnecting from the ADO.NET connection and cleaning up.
It is not strictly necessary to Close() the ISession but you must at least Disconnect() it.
Parameters
return IDbConnection ${WriteSummary(content)}

bool Contains(object obj)

Is this instance associated with this Session?
Parameters
return bool true if the given instance is associated with this Session
object obj an instance of a persistent class

ICriteria CreateCriteria(Type persistentClass, string alias)

Creates a new Criteria for the entity class with a specific alias
Parameters
return ICriteria An ICriteria object
Type persistentClass The class to Query
string alias The alias of the entity

ICriteria CreateCriteria(Type persistentClass)

Creates a new Criteria for the entity class.
Parameters
return ICriteria An ICriteria object
Type persistentClass The class to Query

IQuery CreateFilter(object collection, string queryString)

Create a new instance of Query for the given collection and filter string
Parameters
return IQuery A query
object collection A persistent collection
string queryString A hibernate query

IMultiQuery CreateMultiQuery()

Create a multi query, a query that can send several queries to the server, and return all their results in a single call.
Parameters
return IMultiQuery An IMultiQuery that can return a list of all the results of all the queries. Note that each query result is itself usually a list.

IQuery CreateQuery(string queryString)

Create a new instance of Query for the given query string
Parameters
return IQuery The query
string queryString A hibernate query string

ISQLQuery CreateSQLQuery(string queryString)

Create a new instance of IQuery for the given SQL string.
Parameters
return ISQLQuery An IQuery from the SQL string
string queryString

IQuery CreateSQLQuery(string sql, String[] returnAliases, Type[] returnClasses)

Parameters
return IQuery
string sql
String[] returnAliases
Type[] returnClasses

IQuery CreateSQLQuery(string sql, string returnAlias, Type returnClass)

Create a new instance of IQuery for the given SQL string.
Parameters
return IQuery An IQuery from the SQL string
string sql a query expressed in SQL
string returnAlias a table alias that appears inside {} in the SQL string
Type returnClass the returned persistent class

int Delete(string query, object value, IType type)

Delete all objects returned by the query.
Parameters
return int The number of instances deleted
string query The query string
object value A value to be written to a "?" placeholer in the query
IType type The hibernate type of value.

void Delete(object obj)

Remove a persistent instance from the datastore.
The argument may be an instance associated with the receiving ISession or a transient instance with an identifier associated with existing persistent state.
Parameters
object obj The instance to be removed

int Delete(string query, Object[] values, IType[] types)

Parameters
return int
string query
Object[] values
IType[] types

int Delete(string query)

Delete all objects returned by the query.
Parameters
return int Returns the number of objects deleted.
string query The query string

void DisableFilter(string filterName)

Disable the named filter for the current session.
Parameters
string filterName The name of the filter to be disabled.

IDbConnection Disconnect()

Disconnect the ISession from the current ADO.NET connection.
If the connection was obtained by Hibernate, close it or return it to the connection pool. Otherwise return it to the application. This is used by applications which require long transactions.
Parameters
return IDbConnection ${WriteSummary(content)}

IFilter EnableFilter(string filterName)

Enable the named filter for this current session.
Parameters
return IFilter The Filter instance representing the enabled fiter.
string filterName The name of the filter to be enabled.

IEnumerable Enumerable(string query, Object[] values, IType[] types)

Parameters
return IEnumerable
string query
Object[] values
IType[] types

IEnumerable Enumerable(string query, object value, IType type)

Execute a query and return the results in an interator, binding a value to a "?" parameter in the query string.
Docu.Documentation.Comments.Paragraph Docu.Documentation.Comments.Paragraph
Parameters
return IEnumerable An enumerator
string query The query string
object value A value to be written to a "?" placeholder in the query string
IType type The hibernate type of the value

IEnumerable Enumerable(string query)

Execute a query and return the results in an interator.
Docu.Documentation.Comments.Paragraph Docu.Documentation.Comments.Paragraph
Parameters
return IEnumerable An enumerator
string query The query string

void Evict(object obj)

Remove this instance from the session cache.
Changes to the instance will not be synchronized with the database. This operation cascades to associated instances if the association is mapped with cascade="all" or cascade="all-delete-orphan" .
Parameters
object obj a persistent instance

ICollection Filter(object collection, string filter, Object[] values, IType[] types)

Parameters
return ICollection
object collection
string filter
Object[] values
IType[] types

ICollection Filter(object collection, string filter, object value, IType type)

Apply a filter to a persistent collection, binding the given parameter to a "?" placeholder
A filter is a Hibernate query that may refer to this , the collection element. Filters allow efficient access to very large lazy collections. (Executing the filter does not initialize the collection.)
Parameters
return ICollection A collection
object collection A persistent collection to filter
string filter A filter query string
object value A value to be written to a "?" placeholder in the query
IType type The hibernate type of value

ICollection Filter(object collection, string filter)

Apply a filter to a persistent collection.
A filter is a Hibernate query that may refer to this , the collection element. Filters allow efficient access to very large lazy collections. (Executing the filter does not initialize the collection.)
Parameters
return ICollection The resulting collection
object collection A persistent collection to filter
string filter A filter query string

IList Find(string query)

Execute a query
See List for implications of cache usage.
Parameters
return IList A distinct list of instances
string query A query expressed in Hibernate's query language

IList Find(string query, object value, IType type)

Execute a query, binding a value to a "?" parameter in the query string.
See List for implications of cache usage.
Parameters
return IList A distinct list of instances
string query The query string
object value A value to be bound to a "?" placeholder
IType type The Hibernate type of the value

IList Find(string query, Object[] values, IType[] types)

Parameters
return IList
string query
Object[] values
IType[] types

void Flush()

Force the ISession to flush.
Must be called at the end of a unit of work, before commiting the transaction and closing the session ( Transaction.Commit() calls this method). if the process of synchronising the underlying persistent store with persistable state held in memory.

object Get(Type clazz, object id, LockMode lockMode)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. Obtain the specified lock mode if the instance exists.
Parameters
return object a persistent instance or null
Type clazz a persistent class
object id an identifier
LockMode lockMode the lock mode

object Get(Type clazz, object id)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. (If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.)
Parameters
return object a persistent instance or null
Type clazz a persistent class
object id an identifier

T Get<T>(object id)

Strongly-typed version of Get
Parameters
return T
object id

T Get<T>(object id, LockMode lockMode)

Strongly-typed version of Get
Parameters
return T
object id
LockMode lockMode

LockMode GetCurrentLockMode(object obj)

Determine the current lock mode of the given object
Parameters
return LockMode The current lock mode
object obj A persistent instance

IFilter GetEnabledFilter(string filterName)

Retrieve a currently enabled filter by name.
Parameters
return IFilter The Filter instance representing the enabled fiter.
string filterName The name of the filter to be retrieved.

object GetIdentifier(object obj)

Return the identifier of an entity instance cached by the ISession
Throws an exception if the instance is transient or associated with a different ISession
Parameters
return object the identifier
object obj a persistent instance

IQuery GetNamedQuery(string queryName)

Obtain an instance of IQuery for a named query string defined in the mapping file.
The query can be either in HQL or SQL format.
Parameters
return IQuery An IQuery from a named query string.
string queryName The name of a query defined externally.

ISessionImplementor GetSessionImplementation()

Gets the session implementation.
This method is provided in order to get the implementation of the session from wrapper implementions. Implementors of the interface should return the NHibernate implementation of this method.
Parameters
return ISessionImplementor An NHibernate implementation of the interface

bool IsDirty()

Does this ISession contain any changes which must be synchronized with the database? Would any SQL be executed if we flushed this session?
Parameters
return bool

void Load(object obj, object id)

Read the persistent state associated with the given identifier into the given transient instance.
Parameters
object obj An "empty" instance of the persistent class
object id A valid identifier of an existing persistent instance of the class

object Load(Type theType, object id)

Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.
You should not use this method to determine if an instance exists (use a query or Get instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.
Parameters
return object The persistent instance or proxy
Type theType A persistent class
object id A valid identifier of an existing persistent instance of the class

object Load(Type theType, object id, LockMode lockMode)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode.
Parameters
return object the persistent instance
Type theType A persistent class
object id A valid identifier of an existing persistent instance of the class
LockMode lockMode The lock level

T Load<T>(object id, LockMode lockMode)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode.
Parameters
return T the persistent instance
object id A valid identifier of an existing persistent instance of the class
LockMode lockMode The lock level

T Load<T>(object id)

Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.
You should not use this method to determine if an instance exists (use a query or Get``1 instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.
Parameters
return T The persistent instance or proxy
object id A valid identifier of an existing persistent instance of the class

void Lock(object obj, LockMode lockMode)

Obtain the specified lock level upon the given object.
Parameters
object obj A persistent instance
LockMode lockMode The lock level

void Reconnect()

Obtain a new ADO.NET connection.
This is used by applications which require long transactions

void Reconnect(IDbConnection connection)

Reconnect to the given ADO.NET connection.
This is used by applications which require long transactions
Parameters
IDbConnection connection An ADO.NET connection

void Refresh(object obj)

Re-read the state of the given instance from the underlying database.
Docu.Documentation.Comments.Paragraph Docu.Documentation.Comments.Paragraph
Parameters
object obj A persistent instance

void Refresh(object obj, LockMode lockMode)

Re-read the state of the given instance from the underlying database, with the given LockMode .
It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances.
Parameters
object obj a persistent or transient instance
LockMode lockMode the lock mode to use

void Replicate(object obj, ReplicationMode replicationMode)

Persist all reachable transient objects, reusing the current identifier values. Note that this will not trigger the Interceptor of the Session.
Parameters
object obj
ReplicationMode replicationMode

void Save(object obj, object id)

Persist the given transient instance, using the given identifier.
Parameters
object obj A transient instance of a persistent class
object id An unused valid identifier

object Save(object obj)

Persist the given transient instance, first assigning a generated identifier.
Save will use the current value of the identifier property if the Assigned generator is used.
Parameters
return object The generated identifier
object obj A transient instance of a persistent class

void SaveOrUpdate(object obj)

Either Save() or Update() the given instance, depending upon the value of its identifier property.
By default the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the identifier property mapping
Parameters
object obj A transient instance containing new or updated state

object SaveOrUpdateCopy(object obj)

Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved or does not exist in the database, save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.
Parameters
return object an updated persistent instance
object obj a transient instance with state to be copied

object SaveOrUpdateCopy(object obj, object id)

Copy the state of the given object onto the persistent object with the given identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If there is no database row with the given identifier, save the given instance and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.
Parameters
return object an updated persistent instance
object obj a persistent or transient instance with state to be copied
object id the identifier of the instance to copy to

void Update(object obj)

Update the persistent instance with the identifier of the given transient instance.
${WriteSummary(content)}
Parameters
object obj A transient instance containing updated state

void Update(object obj, object id)

Update the persistent state associated with the given identifier.
An exception is thrown if there is a persistent instance with the same identifier in the current session.
Parameters
object obj A transient instance containing updated state
object id Identifier of persistent instance

Public properties

IDbConnection Connection get;

Gets the ADO.NET connection.
Applications are responsible for calling commit/rollback upon the connection before closing the ISession .
return IDbConnection

FlushMode FlushMode get; set;

Determines at which points Hibernate automatically flushes the session.
For a readonly session, it is reasonable to set the flush mode to FlushMode.Never at the start of the session (in order to achieve some extra performance).
return FlushMode

bool IsConnected get;

Is the ISession currently connected?
return bool

bool IsOpen get;

Is the ISession still open?
return bool

ISessionFactory SessionFactory get;

Get the ISessionFactory that created this instance.
return ISessionFactory

ITransaction Transaction get;

Get the current Unit of Work and return the associated ITransaction object.
return ITransaction