我想在EF中运行一个存储过程。我首先将过程添加到模型并设置返回值。此代码是生成的:
public ObjectResult<Report3> SPSelectReport3(global::System.String stringWhereParameter, Nullable<global::System.Int32> pageIndex, Nullable<global::System.Int32> pageSize)
{
ObjectParameter stringWhereParameterParameter;
if (stringWhereParameter != null)
{
stringWhereParameterParameter = new ObjectParameter("StringWhereParameter", stringWhereParameter);
}
else
{
stringWhereParameterParameter = new ObjectParameter("StringWhereParameter", typeof(global::System.String));
}
ObjectParameter pageIndexParameter;
if (pageIndex.HasValue)
{
pageIndexParameter = new ObjectParameter("PageIndex", pageIndex);
}
else
{
pageIndexParameter = new ObjectParameter("PageIndex", typeof(global::System.Int32));
}
ObjectParameter pageSizeParameter;
if (pageSize.HasValue)
{
pageSizeParameter = new ObjectParameter("PageSize", pageSize);
}
else
{
pageSizeParameter = new ObjectParameter("PageSize", typeof(global::System.Int32));
}
// ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 999999;
return base.ExecuteFunction<Report3>("SPSelectReport3", stringWhereParameterParameter, pageIndexParameter, pageSizeParameter);
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
/// <param name="mergeOption"></param>
/// <param name="stringWhereParameter">No Metadata Documentation available.</param>
/// <param name="pageIndex">No Metadata Documentation available.</param>
/// <param name="pageSize">No Metadata Documentation available.</param>
public ObjectResult<Report3> SPSelectReport3(global::System.String stringWhereParameter, Nullable<global::System.Int32> pageIndex, Nullable<global::System.Int32> pageSize, MergeOption mergeOption)
{
ObjectParameter stringWhereParameterParameter;
if (stringWhereParameter != null)
{
stringWhereParameterParameter = new ObjectParameter("StringWhereParameter", stringWhereParameter);
}
else
{
stringWhereParameterParameter = new ObjectParameter("StringWhereParameter", typeof(global::System.String));
}
ObjectParameter pageIndexParameter;
if (pageIndex.HasValue)
{
pageIndexParameter = new ObjectParameter("PageIndex", pageIndex);
}
else
{
pageIndexParameter = new ObjectParameter("PageIndex", typeof(global::System.Int32));
}
ObjectParameter pageSizeParameter;
if (pageSize.HasValue)
{
pageSizeParameter = new ObjectParameter("PageSize", pageSize);
}
else
{
pageSizeParameter = new ObjectParameter("PageSize", typeof(global::System.Int32));
}
// ((IObjectContextAdapter)).ObjectContext.CommandTimeout = 180;
return base.ExecuteFunction<Report3>("SPSelectReport3", mergeOption, stringWhereParameterParameter, pageIndexParameter, pageSizeParameter);
}
但是,当我运行代码时,我会收到一个超时错误。如何在此代码中设置时间?
使用objectContext的命令时间属性
例如
using (var db = new MyEFEntities())
{
string whereClause = "Id = 12345";
db.CommandTimeout = 180; //in seconds, ideally use a value from your config file e.g. Convert.ToInt32(ConfigurationManager.AppSettings["DbCommandTimeout"]);
var retval = db.SPSelectReport3(whereClause);
//do something here with results
}