I have a user_id table that has a user_id column as an identity column. I have mapped the table like this:
Code:
<class name="Lifecloud.Core.Domain.User, Lifecloud.Core" table="User_ID">
<id name="ID" type="int" column="User_ID" unsaved-value="0">
<generator class="native" />
</id>
<property name="FirstName" column="FirstName" />
<property name="MidInitial" column="MidInitial" />
<property name="LastName" column="LastName" />
<property name="EmailAddress" column="EmailAddress" />
<property name="Status" column="Status" />
<property name="LogonID" column="LogonID" />
<property name="Gender" column="Gender" />
<property name="Age" column="Age" />
<property name="DateCreated" column="DateCreated" />
<property name="DateModified" column="DateModified" />
</class.
My constructor is this:
Code:
public User(string logonid) {
LogonID = logonid;
}
My aspx page has an add button that does this:
Code:
protected void btnAdd_OnClick(object sender, EventArgs e) {
User newUser = new User(txtLogonID.Text);
newUser.FirstName = txtFirstName.Text;
newUser.MidInitial = txtMidInitial.Text;
newUser.LastName = txtLastName.Text;
newUser.EmailAddress = txtEmailAddress.Text;
newUser.Gender = txtGender.Text;
newUser.Age = txtAge.Text;
newUser.DateCreated = DateTime.Now;
IDaoFactory daoFactory = new NHibernateDaoFactory();
IUserDao userDao = daoFactory.GetUserDao();
if (!IsDuplicateOfExisting(newUser, userDao)) {
userDao.Save(newUser);
Response.Redirect("ViewCustomers.aspx?action=added");
}
else {
lblMessage.Text = "<span style=\"color:red\">The Logon ID you provided is already in use.</span> Please change the ID and try again.";
}
}
Is there a way to find out what data NHibernate is trying to send to the database because the add button is gnerating the following error:
Code:
Cannot insert explicit value for identity column in table 'user_id' when IDENTITY_INSERT is set to OFF.
I have looked up the error in various forums and I realize that the command is trying to force something into my identity column but I don't know what it is. I want the MS SQL database to assign the id.
Thank you
Susan