简体   繁体   中英

Equivalent to Hibernate's @embeddable / EF's ComplexTypeConfiguration in NHibernate?

Is there an equivalent to Hibernate's @embeddable annotation / Entity Framework's ComplexTypeConfiguration base class in NHibernate?

I'm aware of the possibility of a 1:1 mapping, but I'm looking for a solution that embeds the values in the parent entitys table.

Based on a quick look at the Hibernate @embeddable attribute, it is basically a component that can be re-used in multiple places. NHibernate does not support this out-of-the-box, but you can accomplish this using Fluent NHibernate's ComponentMap :

Component(x => x.Address, m =>
{
  m.Map(x => x.Number);
  m.Map(x => x.Street);
  m.Map(x => x.PostCode);
});

It doesn't appear that ComponentMap's have quite as much flexibility for overriding column definitions, though you can prefix columns to allow duplicate components in the same entity. (eg ComponentMap with HomeAddress and WorkAddress on a Person.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM