views:

24

answers:

1

Hi, I have a table with primary column as an ID. But that column is not an identity column. All the values are provided explicitly.

Below is my mapping class

 public ObjectTypeMap()
    {
        Table("OBJECTTYPE");
        Id(x => x.ObjectTypeId);
        Map(x => x.Title).Not.Nullable();
        Map(x => x.Description);
    }

but when I try to save this object using session.save, I get an error saying

"Cannot insert the value NULL into column 'ObjectTypeId', table 'DiscoveryWEBTest.dbo.ObjectType'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."

But in my object I am providing the value of ObjectTypeId.

The problem is Fluent NHibernate considers ID mapping as auto-increment column, but in the database ObjectTypeId is not an identity column thats why the insert statement do not get any value and throws null error.

Is there a way with which I can tell the the column is an ID column but its value is not auto-incremented?

Thanks in advance

+2  A: 

Map it like this:

Id(x => x.ObjectTypeId).GeneratedBy.Assigned();
David M
Thanks thats what i wanted.I am new to this and still exploring it.
Ashish
No problem. It actually helps a little I think to know the XML mappings as well, or at least to read about them. You'll find the Fluent equivalents are similarly named, but are not always as well documented.
David M

related questions