Thank you Oskar.
I created a bug report for this and uploaded unit tests. I looked more
into it and it seems like this is an issue that shows up only when I
cast the enum to string in my select list.
I found a workaround, if I declare an alias in the QueryOver<>(() =>
alias) then the problem goes away. I am thinking this is an issue
still, if I am not using casting to string then both tests succeed.
Casting to string throws things off for the first test.
I think I'll just make sure I always declare an alias with the
QueryOver declaration to avoid unexpected issues and time lost
uselessly.
[Test]
public void FilterAndTransformFail()
{
using (ISession session = this.OpenSession())
{
DTO dto = null;
var query = session.QueryOver<DomainClass>()
.SelectList(l => l
.Select(
Projections.Cast(NHibernateUtil.String,
Projections.Property<DomainClass>(a => a.Id))).WithAlias(() => dto.Id)
.Select(a => a.Name).WithAlias(() =>
dto.Name))
.OrderBy(a => a.Id).Asc;
query.Where(a => a.Id !=
ActionEnum.CampaignAddVisibility);
query.TransformUsing(Transformers.AliasToBean<DTO>()).Future<DTO>();
foreach (var q in query.List<DTO>())
{
Console.WriteLine(q.Name);
}
}
}
[Test]
public void FilterAndTransformSuccess()
{
using (ISession session = this.OpenSession())
{
DTO dto = null;
DomainClass dc = null;
var query = session.QueryOver<DomainClass>(() => dc)
.SelectList(l => l
.Select(
Projections.Cast(NHibernateUtil.String,
Projections.Property(() => dc.Id))).WithAlias(() => dto.Id)
.Select(() => dc.Name).WithAlias(() =>
dto.Name))
.OrderBy(() => dc.Id).Asc;
query.Where(() => dc.Id !=
ActionEnum.CampaignAddVisibility);
query.TransformUsing(Transformers.AliasToBean<DTO>()).Future<DTO>();
foreach (var q in query.List<DTO>())
{
Console.WriteLine(q.Name);