This is my scenario:
public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
SuperMercModel SMer = null;
SuperMercDescriptionModel descrSMer = null;
MercModel Merc = null;
MercDescriptionModel descrMerc = null;
var qOver = _HibSession.QueryOver<SuperMercModel>(() => SMer)
.JoinAlias(() => SMer.DescriptionsSM, () => descrSMer,JoinType.LeftOuterJoin)
.Where(() => descrSMer.IDLanguage == IDLanguage)
.JoinAlias(() => SMer.Merc, () => Merc,JoinType.LeftOuterJoin)
.JoinAlias(() => Merc.DescriptionsMer, () => descrMerc,JoinType.LeftOuterJoin)
.Where(() => descrMerc.IDLanguage == IDLanguage)
.OrderByAlias(() => SMer.ID).Asc
.ThenByAlias(() => descrMerc.Description).Asc
.Future<SuperMercModel>();
return qOver;
}
I've encountered the following error
could not resolve property: Description of: SuperMercModel
It's strange, the Description field is in the MercDescriptionModel class not in the SuperMercModel class.
I'm using aliases to create a multiple-join and multiple-order-by query.
Your original code should work without using SQL if you change your OrderByAlias
and ThenByAlias
to regular OrderBy
and ThenBy
clauses. I had this same issue and that resolved it for me.
I've solved it using HQL Here the code
public IEnumerable<ISuperMerc> getSuperMercTree(string IDLanguage)
{
string hql = string.Empty;
hql = "select SM from SuperMercModel SM"
+ " left join fetch SM.DescriptionsSM DSM"
+ " left join fetch SM.Merc ME"
+ " left join fetch ME.DescriptionsMer DME"
+ " where DSM.IDLanguage = :IDLanguage "
+ " and DME.IDLanguage = :IDLanguage "
+ " order by SM.ID asc, DME.Description asc";
IQuery query = _HibSession
.CreateQuery(hql)
.SetString("IDLanguage ", IDLanguage );
IList<SuperMercModel> result = query.List<SuperMercModel>();
return result;
}
I hope it's helpful for someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With