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);
        }

posted @ 2008-01-14 00:19  shiningrise  阅读(1063)  评论(1编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css