I am calling a stored procedure with ISession.CreateSQLQuery.
Then i use
SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article))).List<Article>().ToList()
The problem with this approach is that it AliasToBeanResultTransformeronly maps the table Articleto the class Articleone to one.
public class Article : Entity
{
public virtual string Description { get; set; }
}
public class Entity
{
public virtual int Id { get; set; }
}
public class ArticleRepository : Repository<Article>, IArticleRepository
{
private ISession _session;
public ArticleRepository(ISession session) : base(session)
{
_session = session;
}
public List<Article> GetByDescription(string description)
{
return _session
.CreateSQLQuery("EXEC ArticlesByDescription :Description")
.SetString("Description", description)
.SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article)))
.List<Article>().ToList();
}
}
But my primary key is Articlecalled in my table ArticleId, therefore it AliasToBeanResultTransformerthrows an exception.
Could not find installer for property 'ArticleId' in class 'Core.DomainModels.Article'
Is there a way to reuse FluentNhibernateMapping when using CreateSqlQuery?
EDIT:
The Nhibernate documentation describes how you can use an already matched entity with hbm files.
<sql-query name="GetProductsByCategoryId">
<return class="Product" />
exec dbo.GetProductsByCategoryId :CategoryId
</sql-query>
, ?!