George Silva
George Silva

Reputation: 3484

Nhibernate beginner - asking for directions

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 <map> and <list> but these did not gave me all the options in .

Upvotes: 0

Views: 119

Answers (2)

Martin R-L
Martin R-L

Reputation: 4047

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

Upvotes: 2

David M
David M

Reputation: 72880

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?

Upvotes: 3

Related Questions