我可以在 .Net 中使用没有 EF 的存储过程吗?如果是,那么如何?
Can I use Store procedure without EF in .Net, If yes then How?
1) 我可以在 .Net 中使用没有 EF 的存储过程吗?如果可以,那么如何?
我是开发新手,正在开发 windows 应用程序,我正在使用 ADO.Net 数据集访问数据,但现在我的 windows 应用程序 运行 很慢,我想加快速度up它的数据访问过程...
您可以使用SqlCommand执行sql命令和存储过程。
但在阅读示例之前...
请注意
使用存储过程而不是普通命令或 entity framework,您的应用程序的性能通常不会改变。 Entity framework 本身没有性能问题。
您应该会在其他地方找到您的性能问题。
您可以以糟糕的方式使用任何好的工具。所以换工具不是最终的解决办法。解决方案可能是以正确的方式使用正确的工具。
存储过程示例
例如你可以看到 this sample:
SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlConnection1;
//If your procedure has parameters you can add parameters too
//cmd.Parameters.AddWithValue("parameter", "value");
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
sqlConnection1.Close();
1) 我可以在 .Net 中使用没有 EF 的存储过程吗?如果可以,那么如何? 我是开发新手,正在开发 windows 应用程序,我正在使用 ADO.Net 数据集访问数据,但现在我的 windows 应用程序 运行 很慢,我想加快速度up它的数据访问过程...
您可以使用SqlCommand执行sql命令和存储过程。 但在阅读示例之前...
请注意
使用存储过程而不是普通命令或 entity framework,您的应用程序的性能通常不会改变。 Entity framework 本身没有性能问题。 您应该会在其他地方找到您的性能问题。
您可以以糟糕的方式使用任何好的工具。所以换工具不是最终的解决办法。解决方案可能是以正确的方式使用正确的工具。
存储过程示例
例如你可以看到 this sample:
SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlConnection1;
//If your procedure has parameters you can add parameters too
//cmd.Parameters.AddWithValue("parameter", "value");
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
sqlConnection1.Close();