ActiveRecord多表查询
当from中有多个表时,而select 中只需要一个表中的所有数据,不必像sql一样用*,只要把类名写出来就行,摸索出来的经验,记下,希望对大家有帮助.
见下面查询,特别是加红部分.
[DataObjectMethod(DataObjectMethodType.Select)]
public static ZjcXueshenghuojiang[] List(int xuenian, int xueqi,long banjiId,long banjiStudentId)
{
//BaseBanjiStudent stu = new BaseBanjiStudent();
//stu.BanjiStudentid
string strHql = @"Select huojiang from ZjcXueshenghuojiang huojiang , BaseBanjiStudent stu ";
strHql += " where huojiang.Xuenian = :xuenian and huojiang.Xueqi = :xueqi ";
strHql += " and huojiang.BanjiStudentId = stu.BanjiStudentid and stu.BaseBanji.Banjiid = :banjiId ";
// strHql += " order by huojiang.StartDate DESC ";
SimpleQuery query = new SimpleQuery(
typeof(ZjcXueshenghuojiang), strHql);
query.SetParameter("xuenian", xuenian);
query.SetParameter("xueqi", xueqi);
query.SetParameter("banjiId", banjiId);
return (ZjcXueshenghuojiang[])ExecuteQuery(query);
}