NHibernate: lazy loaded properties?

后端 未结 2 963
死守一世寂寞
死守一世寂寞 2021-01-14 07:23

NHibernate question:

Say I have a SQL table Person and it has a Picture column ( OLE Object ) . I have a class Person and it has : byte[] Picture attribute.

相关标签:
2条回答
  • 2021-01-14 07:53

    It appears that this feature just landed in the NHibernate trunk:

    http://ayende.com/Blog/archive/2010/01/27/nhibernate-new-feature-lazy-properties.aspx

    0 讨论(0)
  • 2021-01-14 08:08

    I have not found any way to get this to work, but the following two ways may help you around the problem you imply:

    • You can map two classes for the same table, one including the byte array, the other not.

    • You can include a many-to-one property mapping to the same table, where the child class has the byte array included, and you then access the binary using Person.PersonPicture.Picture rather than just Person.Picture; the intermediate class can now be lazy loaded.

    Neither is ideal, but they do work. Short answer - collections and many-to-one properties can be lazy loaded, straight properties not.

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