Hi,
I have problem to set an expression to an alias when using conjunction.
I'm using this code:
Code:
public IList<T> GetObjects(ICriterion[] criterions, int skip, int take, out int recordCount)
{
try
{
Conjunction con = Expression.Conjunction();
if (criterions != null)
{
foreach (ICriterion c in criterions)
{
if (c != null)
con.Add(c);
}
}
int count = (int)NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(T))
.Add(con)
.SetProjection(Projections.RowCount()).UniqueResult();
recordCount = count;
ICriteria criteria = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(T));
criteria.Add(con);
if (aliasParams != null)
{
foreach (AliasParam ap in aliasParams)
criteria.CreateAlias(ap.AssiciationPath, ap.Alias);
}
if (skip > 0)
criteria.SetFirstResult(skip);
if (take > 0)
criteria.SetMaxResults(take);
return criteria.List<T>();
}
catch (Exception)
{
throw;
}
}
Code:
private void BindRepeater()
{
ForumThreadDao.AliasParams.Add(new AliasParam("Forum", "f"));
ICriterion[] cri = {
Expression.Eq("f.IsEnabled", true),
Expression.Eq("f.SiteLanguage", UserInfo.CurrentLanguage)
};
int recordCount;
ForumRepeater.DataSource = ForumThreadDao.GetObjects(cri, 0, 10, out recordCount);
ForumRepeater.DataBind();
}
The problem is that the criterion is set before the alias and because of that I'm getting:
could not resolve property: f of: Entities.ForumThread
How can I change the code?