EF调用sql语句

1.连接数据库

EF调用sql语句

 

 

2.在Dal进行调用sql语句

 

 

public List<UserInfo> PageShow(out int totalcount,out int totalpage, string uname,int pageindex= 1,int pagesize =3)
        {
            SqlParameter[] sqls =
            {
                new SqlParameter("@pageindex",pageindex),
                new SqlParameter("@pagesize",pagesize),
                new SqlParameter("@uname",uname==null?"":uname),
                new SqlParameter("@totalcount",System.Data.SqlDbType.Int),
                new SqlParameter("@totalpage",System.Data.SqlDbType.Int)
            };
            sqls[3].Direction = System.Data.ParameterDirection.Output;
            sqls[4].Direction = System.Data.ParameterDirection.Output;
            var list = db.Database.SqlQuery<UserInfo>("exec P_Show @pageindex,@pagesize,@uname,@totalcount out,@totalpage out", sqls).ToList();
            totalcount = (int)sqls[3].Value;
            totalpage = (int)sqls[4].Value;
            return list;
        }

 

上一篇:C# EF


下一篇:.NET 使用EF执行存储过程你知道几种?