views:

507

answers:

2

How do I specify with fluent nHbiernate mapping for a table that doesn't have an identity column?

I want something like this:

public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap
{
    public CustomerNewMap()
    {
        WithTable("customers_NEW");
        Not.LazyLoad();
        Not.Id(); // this is invalid...
        Map(x => x.Username);
        Map(x => x.Company);
    }
}

Cheers in advance

Ollie

+2  A: 

Yes, I do mean no primary key defined in the database, (no much defined in the database)

But I found the answer to be:

  public CustomerNewMap()
  {
        WithTable("customers_NEW");
        Not.LazyLoad();
        Id(x => x.Username).GeneratedBy.Assigned();
        Map(x => x.Company);
  }

Ta

Ollie

AWC
if i try this all objects with the same key (in your example x.Username) are actually copies of the first that gets retrieved from the DB.
blindmeis
A: 

I found I had to explicitly set a column name in a similar case. Something like

  Id(x => x.Username).Column("Username").GeneratedBy.Assigned();
Christopher Stott