开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜