c# - How to map a Collection<T> in NHibernate? -


I have a class contact, a class class with class and a class called supplier. Both the customer and the supplier category receive from the contacts.

The customer has a 0 ... N connection with the order. I want to keep the property of a collection on the customer and it has been mapped in the same table in NHibernate.

How is this done in NHibernate (version 2.0.1 GA)?

(ps: Using .NET 3.5 SP1, VS2008 SP1)

This is done in such a way:

Create your own class like this:

  Public class customers: contact {private ISAT & lt; Order & gt; _orders = new hashset & lt; Order & gt; (); Public collection & lt; Order & gt; Order {Return to New List & lt; Order & gt; (_order); } // noamayili i am a readonly selection and lieutenant; T & gt; Instead of collection & lt; T & gt; // Since I want to avoid users who place orders in the archive. // If your relationship is bi-directional, then you have to set the other // end of the association, so that the programmer To hide / I always add and am; Remove methods (see below) Public Zero AddOrder (order o) {if (o! = Tap & amp; _orders.Contains (o) == incorrect) {o.Customer = this; _orders.Add (o); }}}  

In your mapping, you specify it:

  & lt; Set name = "order" table = "orderstable" access = "field camelcase-underscore" inverse = "true" & gt; & Lt; Major column = "..." /> & Lt; One-to-many classes = "order". /> & Lt; / Set & gt;  

You use heritage, so you should definitely take a look at various positives in relation to inheritance-mapping in NHibernate, and select the best strategy for your situation. :

About Set & amp; Bag Semantics: - When you map a group as a set, you can ensure that all organizations in the mapped collection are unique, that is, NHibernate will ensure that, during an example reorganization , Will not duplicate the collection. - When you map the collection as a bag, then it is possible that only one unit is included in your collection, and then once you load the object with DB.

  • A set is a collection of different objects as a whole, a valid example of a set (of letters) is: {a, b, c, d}. Each letter actually comes once.
  • A bag is a generalization of a set. A bag member can have more than one member, while each member has only one subscription. A valid example of a bag is {a, a, a, b, c, c, d, ...}.
This letter is shown more than once in the bag

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -