1

I am upgrading to NHibernate 3.2. I was using Fluent NHibernate but I don't see a new build for NH 3.2. I am looking at using the included Conform mapper but it does not appear to allow for a composite id. I can't change the database so I have a constraint.

In Fluent NHibernate I had this (names changed for example only):

        Schema("MY_SCHEMA");
        Table("MY_TABLE");
        CompositeId()
            .KeyProperty(x => x.CompanyId, "COMPANY_ID")
            .KeyProperty(x => x.OrderId, "ORDER_ID")
            .KeyProperty(x => x.OrderDate, "ORDER_DATE")
            .KeyProperty(x => x.ProgramId, "PROGRAM_ID");

How would I do this with Conform in NH 3.2?

Thanks, Paul

Paul Speranza
  • 2,302
  • 8
  • 26
  • 43
  • 1
    There is a build of FNH for NH 3.2. There is a NuGet package for this: http://nuget.org/List/Packages/FluentNHibernate/1.3.0.717 – Cole W Oct 25 '11 at 17:01

1 Answers1

4

You can try with:

mapper.Class<YourEntity>(m=>{
m.Table("MY_TABLE");
m.Schema("MY_SCHEMA");
m.ComposedId(cid=>
{
  cid.Property((e)=>e.CompanyId);
  cid.Property((e)=>e.OrderId);
   cid.Property((e)=>e.OrderDate);
//others...
});
});

And, I'm just guessing since I can't figura out your db, you would probably map the single portion of the key a many-to-one ( ie the old key-many-to-one you would write in hbm ), in order to do so, use cid.ManyToOne() instead of cid.Property(..);

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • Felice, Thank you. You led me right to it. My solution looks like this : ComposedId(cid => { Property(x => x.CompanyId, e => e.Column("COMPANY_ID")); Property(x => x.OrderId, e => e.Column("ORDER_ID")); }); etc – Paul Speranza Oct 25 '11 at 18:33
  • @Paul I'm happy I helped to solve your problem, I would point to the fact you can automaticaally generate the column names since you seems have a convention: have a look here http://www.felicepollano.com/2011/09/01/UsingNH32MappingByCodeForAutomaticMapping.aspx not *exactly* your case, but I'm sure you can take some idea from it. – Felice Pollano Oct 25 '11 at 19:29