Skip to content

Instantly share code, notes, and snippets.

View gist:652089
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Concepts.ConsoleApp
{
class Program
{
/*
@Itslet
Itslet / Global.asax.cs
Created Oct 31, 2010
Fluent Nhibernate session per request
View Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Context;
View PersonController.cs
//
// GET: /Person/
public ActionResult Index()
{
var session = FeestBeest.Web.MvcApplication.SessionFactory.GetCurrentSession();
using (session.BeginTransaction())
{
var persons = session.CreateCriteria(typeof(Person))
.List<Person>();
foreach (var p in persons)
View Person.cs
using Iesi.Collections.Generic;
namespace Concepts.Core
{
public class Person : Entity
{
public virtual string GivenName { get; set; }
public virtual string SurName { get; set; }
public virtual string SurNamePrefix { get; set; }
public virtual string OfficialName { get; set; }
View Address.cs
using Iesi.Collections.Generic;
namespace Concepts.Core
{
public class Address : Entity
{
public virtual string StreetName { get; set; }
public virtual string StreetNumber { get; set; }
public virtual string PostcalCode { get; set; }
public virtual string City { get; set; }
View PersonAddress.cs
namespace Concepts.Core
{
public class PersonAddress : Entity
{
public virtual Person Person { get; set; }
public virtual Address Address { get; set; }
public virtual string Remark { get; set; }
public virtual bool IsPostal { get; set; }
public virtual DateTime? ValidFrom { get; set; }
public virtual DateTime? ValidTo { get; set; }
View Person.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Concepts.Core"
namespace="Concepts.Core">
<class name="Person">
<id name ="Id">
<generator class="guid.comb"></generator>
</id>
<property name="GivenName"></property>
<property name="SurName"></property>
View PersonAddress.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Concepts.Core"
namespace="Concepts.Core">
<class name="PersonAddress">
<id name ="Id">
<generator class="guid.comb"></generator>
</id>
<property name="Remark"></property>
<property name="IsPostal"></property>
View Address.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Concepts.Core"
namespace="Concepts.Core">
<class name="Address">
<id name ="Id">
<generator class="guid.comb"></generator>
</id>
<property name="StreetName"></property>
<property name="StreetNumber"></property>
View Program.cs
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using Concepts.Core;
namespace Concepts.Tasks
{
class Program
{
public static void createDatabase()