I Invoke a stored procedure using ISession.CreateSQLQuery
.
Then I use
SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article))).List<Article>().ToList()
The problem with this approach is that the AliasToBeanResultTransformer
only maps the Article
table to the Article
class one 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 on my Article
table is called ArticleId
, so that the AliasToBeanResultTransformer
throws an exception.
Could not find a setter for property 'ArticleId' in class 'Core.DomainModels.Article'
Is there a way of reusing the FluentNhibernateMapping when using CreateSqlQuery
?
EDIT:
The Nhibernate Documentation describes how you can use an already mapped entity with hbm files.
<sql-query name="GetProductsByCategoryId">
<return class="Product" />
exec dbo.GetProductsByCategoryId :CategoryId
</sql-query>
I really ask myself why is it not possible to do this just by code?!