开发者

Mapping multiple columns to an array with NHibernate

I have an old database which can't be changed and I am currently using NHibernate.

The problem is that I have a table with multiple columns and I would like to map them into a single array.

Table ID

Price1

Price2

Price3

Price4

[...]

The class will be the follow开发者_如何学JAVAing:

public class MyClass {
  public int Id { get; set; }
  public decimal[] Prices { get; set; }
}

Is it possible?

I must only read data and I don't actually need to set/save that property.

I have tried many mappings but I couldn't find an answer.


well, this is only a workaround, and is pretty dirty, but I think it might work:

public class MyClass {
  public virtual int Id { get; set; }
  protected virtual decimal Price1 { get; set; }  
  protected virtual decimal Price2 { get; set; }  
  protected virtual decimal Price3 { get; set; }  
//...
  public decimal[] Prices 
  { get 
    {
      return new decimal[] {Price1, Price2, Price3};
    }
  }
}

but, there might be a more sophisticated answer using NH's mapping abilities that I don't know of.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜