0

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);
}

しかし、コードを実行すると、タイムアウト エラーが発生します。このコードでタイムアウトを設定する方法は?

4

1 に答える 1

0

ObjectContext の CommandTimeout プロパティを使用する

例えば

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
}
于 2013-05-07T11:20:05.693 に答える