Skip to content

Instantly share code, notes, and snippets.

View kieransenior's full-sized avatar

Kieran Senior kieransenior

View GitHub Profile
@kieransenior
kieransenior / full-example-nh.cs
Created August 9, 2011 11:33
Full example of NH in use
public static ModelMapper GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<YourClass>(yc =>
{
// your configurations here, for example:
yc.Id(x => x.YourClassID, map =>
{
map.Column("YourClassID");
@kieransenior
kieransenior / full-map-example.cs
Created August 9, 2011 11:28
Full mapping example
mapper.Class<Person>(c =>
{
c.Id(x => x.PersonID, map =>
{
map.Column("PersonID");
map.Generator(Generators.Identity);
});
c.Property(x => x.Name);
c.Property(x => x.Address);
@kieransenior
kieransenior / nh32-example-mapping.cs
Created August 9, 2011 11:26
NH 3.2 Mapping Configuration
ca.List(x => x.Children, map =>
{
map.Key(k => k.Column("Parent"));
map.Index(i => i.Column("Position"));
map.Cascade(Cascade.All);
},
e => e.OneToMany());
@kieransenior
kieransenior / create-session-factory-nh3.2.cs
Created August 9, 2011 11:17
Creating a session factory using NHibernate 3.2
private static ISessionFactory CreateSessionFactory()
{
string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
var configure = new Configuration();
configure.CurrentSessionContext<CallSessionContext>();
configure.DataBaseIntegration(x =>
{
x.Dialect<MsSql2008Dialect>();
@kieransenior
kieransenior / model-management-helper-method.cs
Created June 28, 2011 07:42
Model Management Blog Example - Helper Method
public class Helpers
{
public static string PopulationGroup(int population)
{
if(population < 100)
return "Small";
else if(population >= 100 && population < 500)
return "Medium";
else
return "Large";
@kieransenior
kieransenior / extension-methods-example.cs
Created June 28, 2011 07:34
Model Management Blog Example - Extension Method
public static string PopulationGroup(this City city)
{
if(city.population < 100)
return "Small";
else if(city.population >= 100 && city.population < 500)
return "Medium";
else
return "Large";
}
@kieransenior
kieransenior / gist:1039581
Created June 22, 2011 06:14
Model Management Partial Class Example
public partial class City
{
public string PopulationGroup()
{
if(this.population < 100)
return "Small";
else if(this.population >= 100 && this.population < 500)
return "Medium";
else
return "Large";
@kieransenior
kieransenior / gist:1039578
Created June 22, 2011 06:09
Model Management Blog Example
public class City : MyProject.Models.City
{
public string PopulationGroup()
{
if(this.population < 100)
return "Small";
else if(this.population >= 100 && this.population < 500)
return "Medium";
else
return "Large";