Tag: NHibernate

Nhibernate Explained

http://knol.google.com/k/knol/system/knol/pages/SearchToolkit?show=off&loc0=on&loc1=on&loc2=on&loc3=on&loc4=on&loc5=on&loc6=on&loc7=on&loc8=on&back=1nr4enxv3dpeq.6&url=/k/fabio-maulo/-/1nr4enxv3dpeq/0&restrict=3&language=0&


NHibernate Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using Castle.Core;
using Castle.DynamicProxy;
using NHibernate.Bytecode;

namespace HiberDriver
{
class Program
{
static void Main(string[] args)
{
Configuration cfg = new Configuration();
cfg.AddAssembly(“HiberClass”);
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();

HiberClass.User newUser = new HiberClass.User();
newUser.Id = “joe_cool”;
newUser.UserName = “Joseph Cool”;
newUser.Password = “abc123″;
newUser.EmailAddress = “joe@cool.com”;
newUser.LastLogon = DateTime.Now;

// Tell NHibernate that this object should be saved
session.Save(newUser);

// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
// open another session to retrieve the just inserted user
session = factory.OpenSession();


NHibernate Sample Config File

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>

<!– Configuration Sections In This File –>
<configSections>

<!– NHibernate Section –>
<section
name=”hibernate-configuration”
type=”NHibernate.Cfg.ConfigurationSectionHandler,NHibernate”
/>
</configSections>

<!– NHibernate Configuration –>
<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″>
<session-factory>
<property name=”connection.provider”>
NHibernate.Connection.DriverConnectionProvider
</property>
<property name=”dialect”>
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name=”connection.driver_class”>
NHibernate.Driver.SqlClientDriver
</property>
<property name=”connection.connection_string”>
Data Source=(local)\SQLExpress;Initial Catalog=NHibernate;Integrated Security=True;Pooling=False
</property>
<property name=’proxyfactory.factory_class’>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>

<!– Log4Net Configuration –>

</configuration>
<!–<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<configSections>
<section
name=”nhibernate”
type=”System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″
/>
</configSections>


  • Cloud World

  • Custom Search



  • Cyberbrutus
    iDream theme by Templates Next | Powered by WordPress

    Switch to our mobile site