开发者

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="TrechosIte开发者_高级运维m" 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 .


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?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜