Nhibbench 3.0 cookbook learning notes set

Source: Internet
Author: User

Nhibernate supports four sets:

1 bags

The data in bags can be repeated and the order in bag is not important. For example, a bag set of actorrole may contain actor role 1, actor role 2, actor role 3, actor role 1,
Actor role 4, and actor role 1, which can contain repeated items. The following is a typical bag ing:

<BagName= "Actors"><KeyColumn= "Movieid"/><One-to-leastClass= "Actorrole"/></Bag>

In the corresponding class, the implementation of bag can be ilist, icollection, or even ienumerable.

Because the data in the bag is repeatable, we cannot use a simple SQL statement such as: delete from actors where actorroleid = '1' to delete a piece of data, if this statement is executed, all three actor role 1 entities are deleted.

To solve this problem, Nhibernate provides idbag. In idbag, each entity is assigned a poid to uniquely identify the entity.

     <  Idbag  Name  = "Actors"  >        <  Collection-ID  Column  = "Actorrolebagid"  Type  = "Int64"  >          < Generator  Class  = "HiLo"   />        </  Collection-ID  >        <  Key  Column  = "Movieid"  />        <  One-to-least  Class  = "Actorrole"  />     </  Idbag  > 

In this way, you can delete a unique entity like executing this statement: delete from actors where actorrolebagid = '2.

2 lists

The data in the list is also repeatable, but unlike the bag, the location of the data is meaningful. A list may be set to index 0 to actor role 1, Index 1 to actor role 2, index 2 to actor role 3, index 3 to actor role 1, and index 4 to actor role 4, index 5 is actor role 1. A typical list ing is as follows:

 <  List  Name  = "Actors"  >        <  Key Column  = "Movieid"   />        <  List-Index  Column  = "Actorroleindex"   />        <  One-to-least  Class  = "Actorrole"  />   </  List  > 

In the corresponding class, the List Implementation should be ilist.
3 sets

The data in the set is not allowed to be repeated, and the data location does not matter. In a set, there may be actor role 1, actor role 3, actor role 2, and actor role 4. if you try to insert the entity of actor role 1 into the set, this operation will fail. A typical set ing is as follows:

<SetName= "Actors"><KeyColumn= "Movieid" /><One-to-leastClass= "Actorrole"/></Set>

In the corresponding class, the set implementation should be the Iset from iesi. Collections. dll.
4 Map

MAP is like a dictionary. Every entity in a set has a key and a value, and the key must be unique. A typical ing is as follows:

     <  Map  Name  = "Actors"   >        <  Key  Column  = "Movieid"   />        <  Map-Key  Column  = "Role"  Type  = "String"  />        <  Element  Column  = "Actor"  Type  = "String"  />      </  Map  > 

In the corresponding class, MAP implementation should be idictionary <string, string>.

Of course, there are many data types that allow ing, not just string. The data type of the key or value of a map can even be an object.

     <  Map  Name = "Someproperty"  >        <  Key  Column  = "ID"   />        <  Index-relative-to-Sequence  Class  = "Keyentity"  />        <  Copying-to-Sequence  Class  = "Valueentity"   />     </  Map  > 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.