NHibernate - Execute SQL to populate DTO

后端 未结 2 1694
有刺的猬
有刺的猬 2021-01-05 15:15

I have some instances for reporting where executing sprocs is easier and simpler than complicated QueryOver statements.

I have a DTO, not an entity, that represents

2条回答
  •  温柔的废话
    2021-01-05 16:11

    With CreateSQLQuery, the following would work without any mapping file. Maybe you can give it a try with named queries :

    public class YourDto
    {
        public int YourDtoId { get; set; }
        public string YourDtoTitle { get; set; }
    }
    

    then

    var result = yourNhSession
        .CreateSQLQuery("select yourColumn1 as YourDtoId, yourColumn2 as YourDtoTitle from YOUR_TABLE")
        .SetResultTransformer(Transformers.AliasToBean())
        .List();
    

提交回复
热议问题