EF调用sql语句

2023-03-13,,

1.连接数据库

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

EF调用sql语句的相关教程结束。

《EF调用sql语句.doc》

下载本文的Word格式文档,以方便收藏与打印。