+ public class MyDao
+ {
+ private ISessionManager sessionManager;
+
+ public MyDao(ISessionManager sessionManager)
+ {
+ this.sessionManager = sessionManager;
+ }
+
+ public void Save(Data data)
+ {
+ using(ISession session = sessionManager.OpenSession())
+ {
+ session.Save(data);
+ }
+ }
+ }
+
+
+ Move("b/a.txt", "c/a.txt")
+ Move("b/a.txt", "c") // given c either is a directory or doesn't exist, otherwise it overwrites the file c
+ Move("b/a.txt", "c/") // c must be a directory and might or might not exist. If it doesn't exist it will be created.
+
+ {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
+ i.e. 8-4-4-4-12 hex digits with curly brackets.
+ C:../parent/a.txt
, otherwise, for all paths,
+ this property equals
+ <component id="BasketView"
+ service="Castle.ShoppingCart.IBasketView, Castle.ShoppingCart"
+ type="Castle.ShoppingCart.BasketView, Castle.ShoppingCart"
+ lifestyle="transient"
+ virtualPath="~/Views/BasketView.ascx"
+ />
+
+
+ ComponentModel model, IKernel kernel,
+ ComponentInstanceDelegate onCreation,
+ ComponentInstanceDelegate onDestruction
+
+
+ kernel.Register(Component.For<IService>().ImplementedBy<DefaultService>());
+
+
+ public class SimplePublisher
+ {
+ public event PublishEventHandler Event;
+
+ public void Trigger()
+ {
+ if (Event != null)
+ {
+ Event(this, new EventArgs());
+ }
+ }
+ }
+
+
+ public class SimpleListener
+ {
+ private bool _listened;
+ private object _sender;
+
+ public void OnPublish(object sender, EventArgs e)
+ {
+ _sender = sender;
+ _listened = sender != null;
+ }
+
+ public bool Listened
+ {
+ get { return _listened; }
+ }
+
+ public object Sender
+ {
+ get { return _sender; }
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+
+
+
+ ]]>
+
+
+ var kernel = new DefaultKernel();
+ kernel.Resolver.AddSubResolver(new ArrayResolver(kernel));
+
+
+
+ public class Component
+ {
+ public Component(IService[] services)
+ {
+ }
+ }
+
+
+ var kernel = new DefaultKernel();
+ kernel.Resolver.AddSubResolver(new ListResolver(kernel));
+
+
+
+ public class Component
+ {
+ public Component(IList<IService> services)
+ {
+ }
+ }
+
+
+ service:properties
+
+ Where properties is a list of key value pairs (comma separated). Example:
+
+ protocol:secure=true,version=1.2
+
+ The user can then query for components using the same construction:
+
+ protocol:secure=true
+
+ Or to return all:
+
+ protocol:*
+
+
+ <configuration>
+ <facilities>
+ <facility id="myfacility">
+
+ </facility>
+ </facilities>
+
+ <components>
+ <component id="component1">
+
+ </component>
+ </components>
+ </configuration>
+
+
+
+
+ attributeValue
+
+ propertyValue
+
+
+
+
+
+ attributeValue
+
+ propertyValue
+
+
+
+ container.Register(Component.For<IService>().ImplementedBy<DefaultService>());
+
+ You can use any object that implements the
To make a
It is also standard practice that at least one of your constructors takes an
A collection that contains no duplicate elements. This class models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
A collection that contains no duplicate elements. This interface models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
A collection that contains no duplicate elements. This interface models the mathematical
+
None of the
The following table summarizes the binary operators that are supported by the
Implements an immutable (read-only)
Although this is advertised as immutable, it really isn't. Anyone with access to the
+
Implements a thread-safe
You can use any object that implements the
To make a
It is also standard practice that at least one of your constructors takes an
Implements an immutable (read-only)
Although this is advertised as immutable, it really isn't. Anyone with access to the
+
+ Abstracts ADO.NET batching to maintain the illusion that a single logical batch
+ exists for the whole session, even when batching is disabled.
+ Provides transparent
+ This will be useful once ADO.NET gets support for batching. Until that point + no code exists that will do batching, but this will provide a good point to do + error checking and making sure the correct number of rows were affected. +
+
+ configure.TypeDefinition<TableHiLoGenerator>(c=>
+ {
+ c.Alias = "HighLow";
+ c.Properties = new {max_lo = 99};
+ });
+
+
+ configuration.Configure("path/to/hibernate.cfg.xml");
+
+
+ If this ConnectionProvider is being Finalized (
+ If any subclasses manage resources that also need to be disposed of this method + should be overridden, but don't forget to call it in the override. +
+SELECT
clause SELECT
clause (
+ List results = session.CreateCriteria(typeof(Parent))
+ .Add( Example.Create(parent).IgnoreCase() )
+ .CreateCriteria("child")
+ .Add( Example.Create( parent.Child ) )
+ .List();
+
+
+ IList<Cat> cats = session.QueryOver<Cat>()
+ .Where( c => c.Name == "Tigger" )
+ .And( c => c.Weight > minWeight ) )
+ .List();
+
+
+ IList<Cat> cats = session.QueryOver<Cat>()
+ .Where( c => c.Name == "Tigger" )
+ .And( c => c.Weight > minWeight ) )
+ .List();
+
+ concat(?1, ?2)
to concatenate two strings
+ p1 and p2. Target SQL function will be dialect-specific, e.g. (?1 || ?2)
for
+ Oracle, concat(?1, ?2)
for MySql, (?1 + ?2)
for MS SQL.
+ Each dialect will define a template as a string (exactly like above) marking function
+ parameters with '?' followed by parameter's index (first index is 1).
+
+ This method assumes that the name is not already Quoted. So if the name passed
+ in is
+ If the aliasName is already enclosed in the OpenQuote and CloseQuote then this + method will return the aliasName that was passed in without going through any + Quoting process. So if aliasName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the columnName is already enclosed in the OpenQuote and CloseQuote then this + method will return the columnName that was passed in without going through any + Quoting process. So if columnName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the tableName is already enclosed in the OpenQuote and CloseQuote then this + method will return the tableName that was passed in without going through any + Quoting process. So if tableName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
++ If the schemaName is already enclosed in the OpenQuote and CloseQuote then this + method will return the schemaName that was passed in without going through any + Quoting process. So if schemaName is passed in already Quoted make sure that + you have escaped all of the chars according to your DataBase's specifications. +
+
+ This method checks the string
+ After the OpenQuote and CloseQuote have been cleaned from the string
+ The following quoted values return these results + "quoted" = quoted + "quote""d" = quote"d + quote""d = quote"d +
++ If this implementation is not sufficient for your Dialect then it needs to be overridden. + MsSql2000Dialect is an example of where UnQuoting rules are different. +
++ Author: Ioan Bizau +
++ This dialect probably will not work with schema-export. If anyone out there + can fill in the ctor with DbTypes to Strings that would be helpful. +
+ The dialect defaults the following configuration properties: +
+ Names.Put(DbType, "TEXT" );
+ Names.Put(DbType, 255, "VARCHAR($l)" );
+ Names.Put(DbType, 65534, "LONGVARCHAR($l)" );
+
+ will give you back the following:
+
+ Names.Get(DbType) // --> "TEXT" (default)
+ Names.Get(DbType,100) // --> "VARCHAR(100)" (100 is in [0:255])
+ Names.Get(DbType,1000) // --> "LONGVARCHAR(1000)" (100 is in [256:65534])
+ Names.Get(DbType,100000) // --> "TEXT" (default)
+
+ On the other hand, simply putting
+
+ Names.Put(DbType, "VARCHAR($l)" );
+
+ would result in
+
+ Names.Get(DbType) // --> "VARCHAR($l)" (will cause trouble)
+ Names.Get(DbType,100) // --> "VARCHAR(100)"
+ Names.Get(DbType,1000) // --> "VARCHAR(1000)"
+ Names.Get(DbType,10000) // --> "VARCHAR(10000)"
+
+
+ key="connection.driver_class"
+ value="FullyQualifiedClassName, AssemblyName"
+
+ IDbParameter param = cmd.Parameters["@paramName"]
+ if this is false the code will be
+ IDbParameter param = cmd.Parameters["paramName"]
.
+ + Author: Nikolaos Tountas +
++ In order to use this Driver you must have the Community.CsharpSqlite.dll and Community.CsharpSqlite.SQLiteClient assemblies referenced. +
++ Please check http://code.google.com/p/csharp-sqlite/ for more information regarding csharp-sqlite. +
++ Author: Oliver Weichhold +
++ In order to use this Driver you must have the Npgsql.dll Assembly available for + NHibernate to load it. +
++ Please check the products website + http://www.postgresql.org/ + for any updates and or documentation. +
++ The homepage for the .NET DataProvider is: + http://pgfoundry.org/projects/npgsql. +
++ In order to use this driver you must have the System.Data.SQLite.dll assembly available + for NHibernate to load. This assembly includes the SQLite.dll or SQLite3.dll libraries. +
++ You can get the System.Data.SQLite.dll assembly from http://sourceforge.net/projects/sqlite-dotnet2. +
++ Please check http://www.sqlite.org/ for more information regarding SQLite. +
++ Author: Ioan Bizau +
++ In order to use this Driver you must have the SQLite.NET.dll Assembly available for NHibernate to load it. + You must also have the SQLite.dll and SQLite3.dll libraries. +
++ Please check http://www.sqlite.org/ for more information regarding SQLite. +
+
+ using (ISession session = factory.OpenSession())
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ try
+ {
+ // do some work
+ ...
+ tx.Commit();
+ }
+ catch (Exception e)
+ {
+ if (tx != null) tx.Rollback();
+ throw;
+ }
+ }
+
+
+ This class implements useful common functionality that concrete loaders would delegate to.
+ It is not intended that this functionality would be directly accessed by client code (Hence,
+ all methods of this class are declared
+ The present implementation is able to load any number of columns of entities and at most + one collection role per query. +
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="assigned" />
+
+ <generator class="foreign">
+ <param name="property">AssociatedObject</param>
+ </generator>
+
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="guid.comb" />
+
+ The
+ This code was contributed by Donald Mull. +
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="guid" />
+
The built in strategies for identifier generation in NHibernate are:
+
+ This id generation strategy is specified in the mapping file as
+ <generator class="identity" />
+ or if the database natively supports identity columns
+ <generator class="native" />
+
+ This indicates to NHibernate that the database generates the id when + the entity is inserted. +
+
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="sequence">
+ <param name="sequence">uid_sequence</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="seqhilo">
+ <param name="sequence">uid_sequence</param>
+ <param name="max_lo">max_lo_value</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ The user may specify a
+ It is not intended that applications use this strategy directly. However,
+ it may be used to build other (efficient) strategies. The return type is
+
+ The hi value MUST be fetched in a seperate transaction to the
+ The mapping parameters
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="hilo">
+ <param name="table">table</param>
+ <param name="column">id_column</param>
+ <param name="max_lo">max_lo_value</param>
+ <param name="schema">db_schema</param>
+ </generator>
+
+
+ The
+ The hi value MUST be fecthed in a seperate transaction to the
+ This id generation strategy is specified in the mapping file as
+
+ <generator class="uuid.hex">
+ <param name="format">format_string</param>
+ <param name="seperator">seperator_string</param>
+ </generator>
+
+
+ The
+ The identifier string will consist of only hex digits. Optionally, the identifier string + may be generated with enclosing characters and seperators between each component + of the UUID. If there are seperators then the string length will be 36. If a format + that has enclosing brackets is used, then the string length will be 38. +
+
+
+
+ This class is based on
+ This id generation strategy is specified in the mapping file as
+ <generator class="uuid.string" />
+
+ SetParameter("foo", foo, NHibernateUtil.Int32);
+
+ A name may appear multiple times in the query string.
+ + Entities returned as results are initialized on demand. The first SQL query returns + identifiers only. +
+
+ This is a good strategy to use if you expect a high number of the objects
+ returned to be already loaded in the
+ IList cats = session.CreateCriteria(typeof(Cat))
+ .Add(Expression.Like("name", "Iz%"))
+ .Add(Expression.Gt("weight", minWeight))
+ .AddOrder(Order.Asc("age"))
+ .List();
+
+ You may navigate associations using
+ IList<Cat> cats = session.CreateCriteria<Cat>
+ .CreateCriteria("kittens")
+ .Add(Expression.like("name", "Iz%"))
+ .List<Cat>();
+
+
+ IList<Cat> cats = session.CreateCriteria<Cat>
+ .SetProjection(
+ Projections.ProjectionList()
+ .Add(Projections.RowCount())
+ .Add(Projections.Avg("weight"))
+ .Add(Projections.Max("weight"))
+ .Add(Projections.Min("weight"))
+ .Add(Projections.GroupProperty("color")))
+ .AddOrder(Order.Asc("color"))
+ .List<Cat>();
+
+
+ <sql-query-name name="mySqlQuery">
+ <return alias="person" class="eg.Person" />
+ SELECT {person}.NAME AS {person.name}, {person}.AGE AS {person.age}, {person}.SEX AS {person.sex}
+ FROM PERSON {person} WHERE {person}.NAME LIKE 'Hiber%'
+ </sql-query-name>
+
+
+ If a value is passed in that is wrapped by
+ The value returned by the getter is not Quoted. To get the
+ column name in quoted form use
+ If a value is passed in that is wrapped by
+ The value returned by the getter is not Quoted. To get the
+ column name in quoted form use
case when ... then ... end as ...
+ decode(pkvalue, key1, 1, key2, 2, ..., 0)
+
+ The
+ The
+ This can store the length of the binary data that the
+ This is only needed by DataProviders (SqlClient) that need to specify a Size for the + IDbDataParameter. Most DataProvider(Oralce) don't need to set the Size so a + BinarySqlType would work just fine. +
+
+ This can store the length of the binary data that the
+ This is only needed by DataProviders (SqlClient) that need to specify a Size for the + IDbDataParameter. Most DataProvider(Oralce) don't need to set the Size so a + StringSqlType would work just fine. +
+
+ IList resultWithAliasedBean = s.CreateCriteria(typeof(Enrollment))
+ .CreateAlias("Student", "st")
+ .CreateAlias("Course", "co")
+ .SetProjection( Projections.ProjectionList()
+ .Add( Projections.Property("co.Description"), "CourseDescription" )
+ )
+ .SetResultTransformer( new AliasToBeanResultTransformer(typeof(StudentDTO)) )
+ .List();
+
+ StudentDTO dto = (StudentDTO)resultWithAliasedBean[0];
+
+ + The value stored in the database depends on what your data provider is capable + of storing. So there is a possibility that the DateTime you save will not be + the same DateTime you get back when you check DateTime.Equals(DateTime) because + they will have their milliseconds off. +
+
+ For example - SQL Server 2000 is only accurate to 3.33 milliseconds. So if
+ NHibernate writes a value of
+ Please review the documentation of your Database server. +
+
+ public enum MyEnum
+ {
+ On,
+ Off,
+ Dimmed
+ }
+
+
+
+ public class MyEnumStringType : NHibernate.Type.EnumStringType
+ {
+ public MyEnumStringType()
+ : base( typeof( MyEnum ) )
+ {
+ }
+ }
+
+
+
+ ...
+ <property name="Status" type="MyEnumStringType, AssemblyContaining" />
+ ...
+
+
+ 'T'/'F'
to indicate true/false
.
+ 'Y'/'N'
to indicate true/false
.
+ any
.
+