tags:

views:

43

answers:

2

Hello guys.

I'm starting off with NHibernate now and I still don't have a testable environment.

I would like to know from you, experienced fellows if there is a problem to map IList to an Set in .hbm file.

Like this:

//c#
IList<TrechoItem> trechos_item;

<!-- xml .hbm -->
<set name="TrechosItem" table="trecho_item" lazy="true" inverse="true" fetch="select">
  <key column="id_item"/>
  <one-to-many class="TrechoItem"/>
</set>

Or, in this:

IList<Autor> Autores;

<set name="Autores" lazy="true" table="item_possui_autor">
  <key column="id_item"/>
  <many-to-many class="Autor" column="id_autor"/>
</set>

Is this possible? Or am I doing the wrong thing?

I tried using and but these did not gave me all the options in .

Thanks in advanced

+3  A: 

Normally, a mapping using <set> will use a class deriving from Iesi.Collections.ISet as its collection type. If you want to use IList, you should probably use <bag> for your mapping.

Can I also recommend you take a look at Fluent NHibernate?

David M
Sure i WILL do that! Thanks to you both!
George
+2  A: 

Using a set, e.g. ISet from Iesi.Collections, expresses your intent (uniqueness) much better.

If you don't wan't to depend on that particular 3rd party library, you could instead use the ICollection interface, and the concrete type HashSet from Microsoft, although you'll loose the intention reveling aspect for the interface name (only the concrete impl is clear).

Martin R-L