实体框架 - 什么是当前命令超时值 [英] Entity Framework - what is the current command timeout value

查看:195
本文介绍了实体框架 - 什么是当前命令超时值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为了做到这一点,我将dbContext对象转换成一个ObjectContext,而我的访问CommandTimeout属性。

  int? currentCommandTimeout =((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout; 

此属性的当前值为null,这意味着当前命令超时是底层提供商。


  1. 谁是底层提供商?

  2. 在这种情况下,如何读取(通过EF代码)当前命令超时值?

MSDN新新200新200新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗旗新旗旗新新旗新新旗新新旗新新旗新旗旗新新旗新新旗新新旗旗哨旗新新旗新旗新旗新新旗新新旗新新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新旗新新旗新旗新旗新新旗新新旗新新旗新旗新旗新新旗新新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗但是,这个问题仍然存在。如果可能,您可以通过EF读取缺省情况下的命令超时值。

从MSDN,新新新旗新新新新旗新新旗旗新新新新旗200新新新新旗新新旗200新新新新旗新新旗200新新新新新新新旗200 Chan旗新新新新新新旗新新旗200新新新新旗新新旗新新旗新新款: null value表示将使用底层提供商的默认值。


所以,如果你没有通过代码显式地设置它,或者在你的连接字符串(在MySQL中)传递它,那么它是你的提供者的默认值。



200新X-454545新新新新新新200新200新200新新200新200新200新200新200新200新200新新200新200新200新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新新200新200人新200新新200新200人1992 X- $ b


谁是底层提供商?


底层提供商是您正在传递的您的连接字符串为 providerName

 < connectionStrings> 
< clear />
< add name =Name
providerName =System.Data.ProviderName
connectionString =有效连接字符串 />
< / connectionStrings> X-454545454545.145 X- 20045 X-454545 X-454545 X- 20045 X-45454545新新新新新新新新新新新旗新新旗新新旗新新旗新新200新新新旗新新旗新新旗新新旗新新200新新新新旗新新200新200新新新新旗新新旗新新旗新新新200新新200新新200新200新新新200新200新新200新200人200 200新新新新旗新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗200新新新旗新新旗新新旗2001-新新新新旗新新旗2001-新新新新新新旗新新旗2001-新新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新旗新旗新旗新新新新旗新新旗新新旗新旗新新旗新旗新新新新旗新新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新旗新新旗新新旗新新旗新旗新新旗新旗新新新新旗新旗新新旗新新旗新新旗新5.0 / en / connector-net-programming-mysqlcommand.htmlrel =nofollow> MySql文档
MSDN




  • 默认值为 30秒。 X- 20045454545 X- 200 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- 20045 X- >




默认命令超时可以使用connectionstring属性 Default Command Timeout 在MySQL数据库提供程序的情况下。


I am using Entity Framework 5 and I wish to know the command timeout value.

In order to do so, I cast the dbContext object to an ObjectContext and I access the CommandTimeout property.

int ? currentCommandTimeout = ((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout;

The current value of this property is null which means that the current command timeout is the default value of the underlying provider.

  1. Who is the underlying provider?
  2. How can I read (via EF code) the current command timeout value in this case?

MSDN ObjectContext CommandTimeout Property reference

EDIT: Thank you for explaining how to set the command timeout and finding the default command timeout value in the documentation. However, the question remains open. How, if possible, can you read the command timeout value in case of default, via EF.

解决方案

From MSDN,

  • CommandTimeout property gets or sets the timeout value, in seconds, for all object context operations.
  • A null value indicates that the default value of the underlying provider will be used.

So, if you are not setting it explicitly through code or passing it in your connection string (in MySQL) , then it is the default value of your provider.

If you want to see a non-null value for CommandTimeout, then you will need to pass it in connectionString or set it through code.

Who is the underlying provider?

Underlying provider is the one you are passing in your connectionstring as providerName

<connectionStrings>
  <clear />
  <add name="Name" 
   providerName="System.Data.ProviderName" 
   connectionString="Valid Connection String;" />
</connectionStrings>

Here, System.Data.ProviderName is your underlying provider.

If you are using MySql or MS Sql, According to the MySql Documentation and MSDN,

  • The default value is 30 secs.
  • A value of 0 indicates an indefinite wait and should be avoided.

    Note :

The default command timeout can be changed using the connectionstring attribute Default Command Timeout in case of MySQL database providers.

这篇关于实体框架 - 什么是当前命令超时值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆