Supply default default value in NHibernate mapping for unused columns
My domain object doesn't use 2 non-nullable columns from a table in the database. Bo开发者_如何学Cth of the columns are Guids. Is there a way I can supply a default value for these columns in my mapping file so that I'm able to save my domain object back to the database?
You have a few options:
- Provide your own <sql-insert> in the hbm.xml file. Unfortunately this forces you to take control of all the insert logic.
- Map the columns to private fields within the object that aren't exposed and set the guids when you create a new instance. NHibernate can then save these fields back when inserting. You can also mark the mappings as update="false" so that they're only ever inserted.
- Add default values for those columns in the database schema.
精彩评论