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

前端 未结 2 803
小鲜肉
小鲜肉 2021-01-24 00:42

I have a strange situation I need to persist:

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

What mapping and table structur

相关标签:
2条回答
  • 2021-01-24 01:44

    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 讨论(0)
  • 2021-01-24 01:45

    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.

    0 讨论(0)
提交回复
热议问题