Every mapping requires an Id of some kind. The Id is mapped using the
Id method, which takes a lambda expression that accesses the property on your entity that will be used for the Id. Depending on the return type of the property accessed in the lambda, Fluent NHibernate will make some assumptions about the kind of identifier you're using. For example, if your Id property is an
int, an identity column is assumed. Similarly, if you use a
Guid then a Guid Comb is assumed.
Id(x => x.Id);
Note that the property you supply to
Id can have any name; it does not have to be called "Id," as shown here.
That's the most common scenario for mapping your Id. Customisations can be done by chaining methods off the
Id call. For example, if the column to which the
Id property was to be mapped were not called
Id, we could use the
Column method to specify the name. For explicitly specifying the identity generator, you could use the
Id(x => x.Id) .Column("PersonId") .GeneratedBy.Assigned();
In this example we're specifying that the Id property is mapped to a PersonId column in the database, and it's using an assigned generator.
Fluent NHibernate's interface is designed for discoverability. Everything you need should be easy to find "under" the declaring method using method chains.