NHibernate extensions. Discussed on http://weblogs.asp.net/ricardoperes/archive/2013/02/15/nhibernate-extensibility.aspx.
DateTime extension methods (for Query Over):
- Int32 Day(this DateTime dateTimeProperty): returns the day part of a date
- Int32 Month(this DateTime dateTimeProperty): returns the month part of a date
- Int32 Year(this DateTime dateTimeProperty): returns the year part of a date
Dialect extension methods:
- Dialect GetDialect(this ISessionFactory factory): returns the current Dialect from a session factory
- ISQLFunction RegisterFunction(this ISessionFactory factory, String name): registers a new SQL function that exists on the database
- ISQLFunction RegisterFunction(this ISessionFactory factory, String name, String sql): registers a new SQL function with custom SQL
IEnumerable extension methods:
- IQueryable Query(this IEnumerable collection): executes a server-side query over an entity collection
ISession extension methods:
- T Attach(this ISession session, T entity, LockMode mode = null): attaches a disconnected entity to a session
- Int32 Delete(this ISession session): deletes all entities of a given type
- Boolean DeleteById(this ISession session, Object id): deletes a single entity by its id
- EntityEntry Entry(this ISession session, T entity): returns the First Level Cache entry for a given entity
- void Evict(this ISession session): removes all entities of a given type from the First Level Cache
- void Evict(this ISession session, Object id): removes a single of a given type from the First Level Cache by its id
- IDictionary<String, Object> GetDirtyProperties(this ISession session, T entity): returns all the dirty properties of an entity
- T GetFromCache(this ISession session, Object id): returns an entity of a given type from the First Level Cache by its id
- Boolean HasDirtyProperties(this ISession session, Object entity): checks if an entity has dirty properties
- IEnumerable Local(this ISession session, Status status = Status.Loaded): returns all of the entities of a given type from the First Level Cache
- IQueryable Query(this ISession session, Type entityType): returns a not strongly typed query for a given entity
- void Reset(this ISession session, Object entity): resets an entity to its original definition
IQueryable extension methods (for LINQ):
- IQueryable Between<TSource, TKey>(this IQueryable source, Expression<Func<TSource, TKey>> keySelector, TKey low, TKey high) where TKey : IComparable: returns all entities whose property is between two boundary values
- IQueryable Compare(this IQueryable query, Operand op, String propertyName, Object value = null): returns all entities that match a condition
- IOrderedQueryable OrderBy(this IQueryable query, String propertyName): orders a previously unordered query by a property name as a string
- IOrderedQueryable OrderBy(this IQueryable query, String propertyName, Boolean ascending): orders a previously unordered query by a property name as a string and a flag
- IOrderedQueryable OrderByDescending(this IQueryable query, String propertyName): orders descending a previously unordered query by a property name as a string
- IOrderedQueryable ThenBy(this IOrderedQueryable query, String propertyName): orders an already ordered query by a property name as a string
- IOrderedQueryable ThenBy(this IQueryable query, String propertyName, Boolean ascending): orders an already ordered query by a property name as a string and a flag
- IOrderedQueryable ThenByDescending(this IOrderedQueryable query, String propertyName): orders descending an already ordered query by a property name as a string
String extension methods (for LINQ):
- String Soundex(this String input): applies the SOUNDEX algorithm to a string (SQL Server only)
Copyright Ricardo Peres 2013