Lazy loading a portion of a record with NHibernate

眉间皱痕 提交于 2019-12-24 07:40:15

问题


I'm not sure how to explain this. So here goes...

I'm trying to fit the method for lazy loading blobs as described here but I'm stuck with only one table.

I have a schema (fixed, in a legacy system) which looks something like this:

MyTable
   ID int
   Name char(50)
   image byte

This is on Informix, and the byte column is a simple large object. Now normally I would query the table with "SELECT ID, Name, (image is not null) as imageexists..." and handle the blob load later.

I can construct my object model to have two different classes (and thus two different map definitions) to handle the relationship, but how can I "fool" nhibernate into using the same table to show this one-to-one relationship?


回答1:


Short answer: you can't.

You either need to map it twice or (my preference) create a DTO that has the fields you want. In HQL you'd do something like:

select new MyTableDTO(t.ID, t.name) from MyTable t


来源:https://stackoverflow.com/questions/802251/lazy-loading-a-portion-of-a-record-with-nhibernate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!