我有很多存储过程。 为了使用它们,我创建了一个带有静态方法的静态类,如下所示:
public class DBHandler
{
private static Database db = DatabaseFactory.CreateDatabase("db");
public static DataTable GetItems(long filterId)
{
DbCommand command = db.GetStoredProcCommand("dbo.P_GetItems");
db.AddInParameter(command, "@filter_id", DbType.Int64, filterId);
IDataReader reader = db.ExecuteReader(command);
DataTable dt= new DataTable();
dt.Load(reader, LoadOption.OverwriteChanges);
reader.Close();
return dt;
}
.
.
.
.
}
正如我所写的,我有很多存储过程,重复这段代码很烦人。 有没有更好的方法调用存储过程?
最佳答案
您可以使用命令行实用程序 sqlmetal.exe
自动生成您可以在简单的 LINQ 查询中使用的数据上下文代码。
关于c# - 如何使用存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594816/