views:

230

answers:

2

I'm trying to map a view without an identifier, but nhibernate still generates a sql with the id column (giving me a sql error, since the ID column does not exists in the db). Maybe I'm misunderstanding the Id() constructor?

constructor comments:

Create an Id that doesn't have a corresponding property in the domain object, or a column in the database. This is mainly for use with read-only access and/or views. Defaults to an int identity with an "increment" generator.

public class PersonMapping : ClassMap<Person>
{
    public PersonMapping()
    {
        Table("person");
        ReadOnly();

        Id();
        Map(f => f.Name, "name");
    }
}
A: 

Doesn't work. Id is always in the hibernate query. tryed you fluent 1.1.0.689 version

zyko
A: 

NHibernate requires an ID. The method doc says it creates an ID which has no corresponding property in your domain object - however the database still has an ID.

If you have no field in your table to mark as an identifier (has to be unique..) maybe you can try to identify some columns which can be composed as an composite id.

Given for example a simple link table which links some int to an other int like

A | B
-----
1 | 2
1 | 3
2 | 2

you could use Composite ID as long as all A/B combinations are unique.

public PersonMapping()
{
    [...]
     CompositeId()
         .KeyProperty(x => x.A)
         .KeyProperty(x => x.B);
    [...]
}
Zebi