views:

129

answers:

2

Hi,

We have a multi-tiered application using CSLA Business Objects and NHibernate ORM. In our Business Objects, we hold our collection data members as ICollection<T>, and in our object mapping files we define them as <set>s.

Since NHibernate uses its own concrete types to fetch these collections, we have a problem when these collections reach the client, because we don't reference the NHibernate assembly in the client application (and we don't want to change that).

Is there a way to solve that or somehow force NHibernate to use a .net collection type, or our own collection type, without implementing any NHibernate collection type interface?

Thanks in Advance,

Yaron.

A: 

You can use ICollection<T> and HashSet<T> without referencing Iesi.Collections

Matt Hinze
Don't understand the downvote - this *is* the answer (*).. am I misunderstanding something? (*) besides resolving the clear violation (implied in the question) of the first law of distributed computing . ..
Matt Hinze
A: 

NHibernate needs its own implementations of the collections to manage the persistency states. So you can't change NHibernates behaviour.

We are using WCF, it turns collections to arrays or lists when serializing. If your infrastructure doesn't do this, you need to convert the objects before sending to the client.

It's best to use a DTO (data transfer object) model anyway. You need copy all data from the business model to the DTO model.

If you don't like to have a DTO model, I think you need to exchange your collections. Write a method that exchanges NH's collections with .NET framework collections, eg. using reflection.

Or - you live with the reference to NHibernate on the client.

Stefan Steinegger