EF调用存储过程

然后在Mvc中创建一数据库优先的实体数据模型,

与数据库建立连接


选择所需要的表

找的上下文的名称进行实例化

进行连接存储过程
public List<UserInfo> show(out int totalcount, out int totalpage, string uname, int pageindex, int pagesize)
{
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_page @uname,@pageindex,@pagesize,@totalcount out,@totalpage out ", sqls).ToList();
totalcount = (int)sqls[3].Value;
totalpage = (int)sqls[4].Value;
return list;
}

浙公网安备 33010602011771号