I have table CUSTOMER
where CUSTOMER_ID
is primary key.
Table
CREATE TABLE [CUSTOMER](
[CUSTOMER_ID] [int] NOT NULL,
[START_DATE] [varchar(30)] NOT NULL,
CONSTRAINT [PK_CUSTOMER] PRIMARY KEY CLUSTERED ( [CUSTOMER_ID] ASC .....
Mapping
public class CustomerMap : ClassMap<Customer> {
public CustomerMap()
{
WithTable("CUSTOMER");
Id(x => x.CustomerID, "CUSTOMER_ID");
Map(x => x.Name, "NAME");
}
}
I need to handle assigning of the CustomerID property manually. For example I created new Customer with CustomerID = 777 and name "stackoverflow".
When I call method Session.SaveOrUpdate(customer); I want NHibernate to generate me SQL like this:
INSERT INTO [CUSTOMER] ([CUSTOMER_ID] ,[NAME]) VALUES (777,'stackoverflow')
Unfortunately I'm getting errors.
Main issue here is that Nhibernate tries to generate ID for me. But I want to save my entity exactly with 777.
I think there should be way to setup mapping for Id() some another way so this will allow me do what I want.
Please help.