NHibernate 搜索索引 poco 对象抛出 TransientObjectException
当使用纯 poco 对象调用 FullTextSession 上的 Index 方法时,会抛出以下错误,但与代理对象一起工作正常。
堆栈跟踪:
[TransientObjectException:该实例与此会话没有关联] NHibernate.Impl.SessionImpl.GetIdentifier(Object obj) +500
我试图从 nhibernate select 方法中挤出性能,我得到以下代码:
public virtual IList<T> LoadSearch()
{
return Adapater.Session.QueryOver<T>()
.SelectList(e =>
{
e.Select(x => x.Id);
e.Select(x => x.Title);
e.Select(x => x.Description);
return e;
}).List<object[]>()
.Select(props => new T
{
Id = (Guid)props[0],
Title = (string)props[1],
Description = (string)props[2]
}).ToList();
}
有没有办法返回代理结果?或者如何使列表适应代理列表?
When calling Index method on FullTextSession with plain poco object throws the error below, works fine with proxied object.
Stacktrace:
[TransientObjectException: the instance was not associated with this session]
NHibernate.Impl.SessionImpl.GetIdentifier(Object obj) +500
I'm trying to squeeze the performance out of the nhibernate select method I've got the following code:
public virtual IList<T> LoadSearch()
{
return Adapater.Session.QueryOver<T>()
.SelectList(e =>
{
e.Select(x => x.Id);
e.Select(x => x.Title);
e.Select(x => x.Description);
return e;
}).List<object[]>()
.Select(props => new T
{
Id = (Guid)props[0],
Title = (string)props[1],
Description = (string)props[2]
}).ToList();
}
Is there way to return a proxied result? or some how adapt the list to a proxied list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只能索引与会话关联的对象,即代理实体。
您返回的普通 POCO 并非来自 NH - 因此不与 NH 会话关联。
您可以尝试在每个实体上使用
ISession.Lock(instance, NHibernate.LockMode.None);
将其与会话关联,但我真的不知道这是否有效。I think you can only index objects that are associated with a session, i.e. proxied entities.
The plain POCOs you are returning didn't come from NH - so aren't associated with a NH session.
You could try using
ISession.Lock(instance, NHibernate.LockMode.None);
on each entity to associate it with the session, but I really don't know if that'd work.