开发者

What nhibernate mapping is used for string[] in an entity?

I have a strange situation I need to persist:

public class Person
{
  public string[] Nicknames { get; set; }
}

Wha开发者_运维技巧t mapping and table structure would be best to persist this string array?


You can map arrays directly, but you'll need a few additional columns:

<!-- can live w/o orderby -->
<array name="Nicknames" table="Nicknames" order-by="indexColumn ASC"> 
  <key column="keyColumn"/>
  <index column="indexColumn"/> <!-- position in array -->
  <element column="nickname" type="String"/>
</array>

If you don't have the other columns you need, I would probably persist it as a normal bag or list and expose it as an array from that in the entity.


You can use some logic of yours to achieve the same thing right.. probably adding your own delimiter between the nicknames and then split it by this delimiter once you read it into memory.

public class Person
{
  public string Nicknames { private get; set; }

  public string[] ArrayOfNicknames
  {
    get
    {
        return Nicknames.Split(<your_delimiter>);
    }
  }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜