NHibernate

From no name for this wiki
Revision as of 11:42, 15 November 2012 by Claude (talk | contribs) (resourcen)
Jump to: navigation, search

Konfigurationsdatei Sample

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=(local);Database=nhibernate;Trusted_Connection=true;</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

many to many mapping

Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="ConsoleApplication2"
                   namespace="ConsoleApplication2">

  <class name="MyItem">
    
    <id name="ID" generator="native"/>
    
    <property name="Name" />

    <!-- Many-to-many mapping: OrderItems -->
    <bag name="Tags" 
         table="MyItem_MyTag" 
         cascade="none" 
         lazy="true">
      <key column ="MyItemID" />
      <many-to-many class="MyTag" column="MyTagID" />
    </bag>
    
  </class>

</hibernate-mapping>

Klasse:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    public class MyItem
    {
        public virtual string Name { get; set; }
        public virtual int ID { get; set; }

        IList<MyTag> _tags = new List<MyTag>();
        public virtual IList<MyTag> Tags {
            get
            {
                return this._tags;
            }
            set
            {
                _tags = value;
            }
        }
    }
}

Konfiguration mit fluet configuration

 Cache.ReadOnly().Region("Keep15Min");

resourcen