This is a mirror of official site: http://jasper-net.blogspot.com/

NHibernate 3.2 mapping by code

| Wednesday, June 27, 2012
NHibernate 3.2 will come with its own embedded mapping by code.

If you want know it is not based in fluent-interface, instead it is based on “loquacious”. That said you should understand that it has nothing related with Fluent-NHibernate.

The main idea under the NHibernate’s “sexy mapping” came from my dear ConfORM. In the past year the no conformist red man was running a lot and now I’m ready to transfer most of ConfORM’s intelligence directly inside NHibernate. To continue reading this post you have to run this song.

It’s simple (I’m too sexy)
Simple model

public class MyClass
{
    public int Id { get; set; }
    public string Something { get; set; }
}

Simple mapping

var mapper = new ModelMapper();
mapper.Class<MyClass>(ca =>
{
    ca.Id(x => x.Id, map =>
    {
        map.Column("MyClassId");
        map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
    });
    ca.Property(x => x.Something, map => map.Length(150));
});
 
It’s flexible (I’m too sexy for my application)

You can organize your mapping as you want, class-by-class, different concerns about a class in different places and so on… (yes!! if you are a ConfORM user you know the concept)

var mapper = new ModelMapper();
mapper.Class<MyClass>(ca =>
{
    ca.Id(x => x.Id, map =>
    {
        map.Column("MyClassId");
    });
    ca.Id(x => x.Id, map =>
    {
        map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
    });
    ca.Property(x => x.Something);
    ca.Property(x => x.Something, map => map.Length(150));
});

Read more: HunabKu
QR: Inline image 1

Posted via email from Jasper-net

0 comments: