NHibernate - CreateSQLQuery 异常“没有持久化..”,为什么?
我正在尝试使用 CreateSQLQuery 在 NHibernate 中创建 SQL 查询:
var query = session.CreateSQLQuery(
"select loss.id as loss.Id, loss.start_date as loss.Date, " +
" (select ... limit 1) as loss.Reserve, " +
" (select sum(m.val) ...) as loss.Payment " +
"from LossData loss .. where ...";
// Commenting or uncommenting these doesn't have any effect either
query.AddScalar("Id", NHibernateUtil.Int32);
query.AddScalar("Date", NHibernateUtil.DateTime);
query.AddScalar("Reserve", NHibernateUtil.Double);
query.AddScalar("Payment", NHibernateUtil.Double);
query.AddEntity("loss", typeof(LossQueryDto));
query.SetResultTransformer(Transformers.AliasToBean(typeof(LossQueryDto)));
var list = query.List<LossQueryDto>();
但它给了我一个错误“No persister for: 'LossQueryDto'”。这个查询有什么问题? 我是否需要额外的查询映射?如果是这样,我可以在 Fluent Nhibernate 中定义一个吗?我正在使用 NHibernate 3.1。
Dto本身是这样的:
public class LossQueryDto
{
public virtual int Id { get; set; }
public virtual DateTime Date { get; set; }
public virtual double Reserve { get; set; }
public virtual double Payment { get; set; }
}
谢谢!
I'm trying to create a SQL query in NHibernate using CreateSQLQuery:
var query = session.CreateSQLQuery(
"select loss.id as loss.Id, loss.start_date as loss.Date, " +
" (select ... limit 1) as loss.Reserve, " +
" (select sum(m.val) ...) as loss.Payment " +
"from LossData loss .. where ...";
// Commenting or uncommenting these doesn't have any effect either
query.AddScalar("Id", NHibernateUtil.Int32);
query.AddScalar("Date", NHibernateUtil.DateTime);
query.AddScalar("Reserve", NHibernateUtil.Double);
query.AddScalar("Payment", NHibernateUtil.Double);
query.AddEntity("loss", typeof(LossQueryDto));
query.SetResultTransformer(Transformers.AliasToBean(typeof(LossQueryDto)));
var list = query.List<LossQueryDto>();
But it gives me an error "No persister for: 'LossQueryDto'". What's wrong with this query ?
Do I need an additional mapping for the query ? If so, can I define one in Fluent Nhibernate ? I'm using NHibernate 3.1.
The Dto itself is like this:
public class LossQueryDto
{
public virtual int Id { get; set; }
public virtual DateTime Date { get; set; }
public virtual double Reserve { get; set; }
public virtual double Payment { get; set; }
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不是在查询实体,而是在查询 DTO,因此您可以删除以下内容:
You are not querying entities, but DTO, so you can remove following: