开发者

Mapping multiple columns to an array with NHibernate

开发者 https://www.devze.com 2023-03-03 23:18 出处:网络
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.

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

精彩评论

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

关注公众号