首页 > 代码库 > EF执行存储过程返回DataSet
EF执行存储过程返回DataSet
public static System.Collections.Generic.IEnumerable<TElement> RunSP<TElement>(this Database self, string spName, params SqlParameter[] paras) { System.Collections.Generic.IEnumerable<TElement> entityList = new System.Collections.Generic.List<TElement>(); DataSet set = self.RunSP(spName, paras); if ((set != null) && (set.Tables.get_Count() >= 1)) { entityList = EntityHelper.GetEntityList<TElement>(set.Tables.get_Item(0)); } return entityList; } public static DataSet RunSP(this Database self, string spName, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command = new SqlCommand(spName, connection)) { adapter.set_SelectCommand(command); command.set_CommandType(CommandType.StoredProcedure); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command.Parameters.Add(parameter2); } } DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static DataSet RunSP(this Database self, string spName, SqlTransaction tran, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command = new SqlCommand(spName, connection)) { if (tran != null) { command.set_Transaction(tran); } adapter.set_SelectCommand(command); command.set_CommandType(CommandType.StoredProcedure); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command.Parameters.Add(parameter2); } } DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static System.Collections.Generic.IEnumerable<TElement> RunSql<TElement>(this Database self, string command, params SqlParameter[] paras) { System.Collections.Generic.IEnumerable<TElement> entityList = new System.Collections.Generic.List<TElement>(); DataSet set = self.RunSql(command, paras); if ((set != null) && (set.Tables.get_Count() >= 1)) { entityList = EntityHelper.GetEntityList<TElement>(set.Tables.get_Item(0)); } return entityList; } public static DataSet RunSql(this Database self, string command, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command2 = new SqlCommand(command, connection)) { command2.set_CommandType(CommandType.Text); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command2.Parameters.Add(parameter2); } } adapter.set_SelectCommand(command2); DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static DataSet RunSql(this Database self, string command, SqlTransaction tran, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command2 = new SqlCommand(command, connection)) { if (tran != null) { command2.set_Transaction(tran); } command2.set_CommandType(CommandType.Text); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command2.Parameters.Add(parameter2); } } adapter.set_SelectCommand(command2); DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } }
EF执行存储过程返回DataSet
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。