【发布时间】:2015-07-30 05:07:45
【问题描述】:
我正在学习实体框架和 MVC。我有以下旧代码使用 SQL 适配器连接到数据库并调用存储过程来获取数据。
我应该如何使用实体框架正确重构它?谢谢。
DataSet ds = new DataSet();
string connstr = ConfigurationManager.AppSettings["isr1DSN"];
using (SqlConnection con = new SqlConnection(connstr))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("uspGetAssetUses", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@BaseCode", SqlDbType.VarChar, 5).Value = baseCode;
cmd.Parameters.Add("@Scope", SqlDbType.VarChar, 6).Value = scopeID;
cmd.Parameters.Add("@SortColumn", SqlDbType.VarChar, 20).Value = field;
cmd.Parameters.Add("@Direction", SqlDbType.VarChar, 4).Value = direction;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(ds);
}
}
}
【问题讨论】:
标签: asp.net asp.net-mvc