使用NHibernate延迟加载记录的一部分 [英] Lazy loading a portion of a record with NHibernate

查看:80
本文介绍了使用NHibernate延迟加载记录的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定该如何解释.所以这里去...

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

这是在Informix上,字节列是一个简单的大对象.现在,通常我会使用"SELECT ID, Name, (image is not null) as imageexists..."查询表,并稍后处理blob加载.

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.

我可以将对象模型构造为具有两个不同的类(以及两个不同的映射定义)来处理这种关系,但是如何愚弄" nibernate以使用同一张表来显示这种一对一的关系呢?

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?

推荐答案

简短的回答:不能.

您需要将其映射两次,或者(根据我的喜好)创建具有所需字段的DTO.在HQL中,您可以执行以下操作:

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

这篇关于使用NHibernate延迟加载记录的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆