开发者

NHibernate - CreateSQLQuery exception "No persister for ..", why?

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开发者_如何学Go; set; }
}

Thanks!


You are not querying entities, but DTO, so you can remove following:

query.AddEntity("loss", typeof(LossQueryDto));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜