开发者

Supply default default value in NHibernate mapping for unused columns

开发者 https://www.devze.com 2023-01-28 22:13 出处:网络
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 mappin

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消