EF 调用存储过程实例
Posted su1643
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EF 调用存储过程实例相关的知识,希望对你有一定的参考价值。
IQueryable<TPT_ECN_MSTR> q = db.TPT_ECN_MSTRS.AsNoTracking();
if (_OrdDateFr == DateTime.MinValue && _OrdDateTo == DateTime.MaxValue) return q.Where(p => 1 == 2).ToList();
string usr_user = GetIdentityName();
OracleParameter[] pars = {
new OracleParameter("var_DateFr", OracleDbType.Date),
new OracleParameter("var_DateTo", OracleDbType.Date),
new OracleParameter("var_Vend", OracleDbType.Varchar2),
new OracleParameter("var_ecn_status", OracleDbType.Varchar2),
new OracleParameter("var_part", OracleDbType.Varchar2),
new OracleParameter("var_part_type", OracleDbType.Varchar2),
new OracleParameter("var_po", OracleDbType.Varchar2),
new OracleParameter("var_user", OracleDbType.Varchar2)
};
pars[0].Value = _OrdDateFr;
pars[1].Value = _OrdDateTo;
pars[2].Value = _vend;
pars[3].Value = _ecn_status;
pars[4].Value = _part;
pars[5].Value = _part_type;
pars[6].Value = _po;
pars[7].Value = usr_user;
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GET_ECN_REPORT";
if (pars.Length > 0)
cmd.Parameters.AddRange(pars);
// cmd.Parameters.AddRange(Oparms);
cmd.Connection.Open();
int retCode = cmd.ExecuteNonQuery();
cmd.Connection.Close();
q = q.Where(p => p.TPT_ECN_USER == usr_user);
// 在查询之后,排序和分页之前获取总记录数
pagingInfo.RecordCount = q.Count();
if (pagingInfo.RecordCount > 0 && string.IsNullOrWhiteSpace(pagingInfo.SortField))
{
pagingInfo.SortField = "ECN_VEND";
pagingInfo.SortDirection = "ASC";
}
// 排列和数据库分页
q = SortAndPage<TPT_ECN_MSTR>(q, pagingInfo);
return q.ToList();
以上是关于EF 调用存储过程实例的主要内容,如果未能解决你的问题,请参考以下文章