我正在将使用ADO.NET/ODP.NET的代码迁移到Enterprise Library 6.0。我正在使用增加对ODP.NET支持的EntLibContrib项目。在ADO.NET代码中进行了一些优化,我正在尝试确定如何使用EL调用这些属性。
ADO.NET如下所示:
using (OracleConnection conn = new OracleConnection(_connectionString))
{
using (OracleCommand cmd = new OracleCommand(command, conn))
{
cmd.CommandType = CommandType.Text;
cmd.InitialLOBFetchSize = -1;
cmd.Connection.Open();
OracleDataReader reader = cmd.ExecuteReader();
reader.FetchSize = reader.RowSize * 1000;
reader.Read();
[...]
}
}
EL代码如下:
var database = new DatabaseProviderFactory().CreateDefault();
using (var reader = database.ExecuteReader(CommandType.Text, command))
{
[...]
}
我也在更新存储过程以及示例。
ADO.NET:
using (OracleConnection conn = new OracleConnection(_connectionString))
{
using (OracleCommand cmd = new OracleCommand(command, conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pID", OracleDbType.Int32).Value = eID;
OracleParameter pResults = cmd.Parameters.Add("pResults", OracleDbType.RefCursor, ParameterDirection.Output);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
using (OracleRefCursor cursor = pResults.Value as OracleRefCursor)
{
using (OracleDataReader reader = cursor.GetDataReader())
{
reader.FetchSize = reader.RowSize * 1000;
while (reader.Read())
{
[...]
}
致EL:
var database = new DatabaseProviderFactory().CreateDefault();
using (var reader = database.ExecuteReader("SS.SP_GET_TASKDATA_BY_PRAC", practiceID, firstRow, lastRow))
{
while (reader.Read())
{
[...]
}
如何使用我的EL代码设置FetchSize和InitialLOBFetchSize属性?
答案 0 :(得分:0)
我想这已经很久以来已经解决了,但我认为你可以做到以下几点(至少对于EF5,不确定6):
SQL查询
var cmd = database.GetSqlStringCommand(command);
var ocmd = (OracleCommand)cmd;
ocmd.InitialLOBFetchSize = -1;
using (var reader = database.ExecuteReader(cmd))
{
...
}
存储过程
var cmd = database.GetStoredProcCommand("SS.SP_GET_TASKDATA_BY_PRAC", practiceID, firstRow, lastRow );
var ocmd = (OracleCommand)cmd;
ocmd.InitialLOBFetchSize = -1;
using (var reader = database.ExecuteReader(cmd))
{
...
}
编辑:你也可以用同样的方式在ocmd上设置FetchSize。