HttpClientWebAPI客户端的生命周期应该是多少?为多个调用
设置一个实例是否更好HttpClient?
创建和处理HttpClient每个请求的开销是多少,如下面的示例所示(摘自http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from- a-net-client):
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:9000/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// New code:
HttpResponseMessage response = await client.GetAsync("api/products/1");
if (response.IsSuccessStatusCode)
{
Product product = await response.Content.ReadAsAsync<Product>();
Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);
}
}
Run Code Online (Sandbox Code Playgroud) 我有VS 2013和Microsoft Windows 8.1这个问题出现在上周结束时.没有任何更新或重要更改,当我在VS中执行某些操作时,磁盘使用率达到100%.例如,当我单击"团队资源管理器"窗口中的"签入"按钮时,磁盘使用率会上升到100%.有时通过简单的右键单击文本编辑器就会出现问题.我搜索了大约100%的磁盘使用问题但是在Windows 8.1上有一些关于这个问题的事情,但是在我的计算机中所有应用程序都运行没有任何问题,只是VS2013有"完全磁盘使用"问题.
有关我的系统的一些信息:
操作系统名称:Microsoft Windows 8.1 Pro
操作系统版本:6.3.9600 N/A Build 9600
系统类型:基于x64的PC
处理器:已安装1个处理器.Intel64系列6型号60步进3GenuineIntel~3500 Mhz
物理内存总量:8,131 MB
可用物理内存:3,836 MB
虚拟内存:最大大小:10,947 MB
虚拟内存:可用:5,275 MB
虚拟内存:使用中:5,672 MB
页面文件位置:C:\ pagefile.sys
如何在T-SQL中对位列使用函数SUM()?
当我尝试这样做时,如下所示:
SELECT SUM(bitColumn) FROM MyTable;
Run Code Online (Sandbox Code Playgroud)
我收到错误:
操作数数据类型位对于sum运算符无效.
[Phone]属性的默认有效格式是什么?在数据表中,电话栏是navrchar(16)如果我输入电话#1112223333,我得到"字段不是有效的电话号码".如果我输入01112223333,我会收到"值'11112223333'无效."
另外,如何覆盖它?我知道我可以做这样的事情,但这是这种情况下的最佳做法吗?
[RegularExpression(@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}",ErrorMessage="Invalid Phone Number!")]
Run Code Online (Sandbox Code Playgroud)
相关代码:
[Required]
[Phone]
public string Phone { get; set; }
<div class="editor-field">
@Html.EditorFor(model => model.Phone)
@Html.ValidationMessageFor(model => model.Phone)
</div>
Run Code Online (Sandbox Code Playgroud)
更新 我想当我将手机列从int更改为navrchar时存在映射问题.更新模型是不够的,所以我不得不使用表映射手动更改值.
2019年错误:指定的成员映射无效.'UserDBModel.UserProfile'类型中成员'Phone'的类型'Edm.Int32 [Nullable = False,DefaultValue =]'与'SqlServerCe.nvarchar不兼容[Nullable = False,DefaultValue =,MaxLength = 16,Unicode = True ,"FixedLength = False]'成员'Phone',类型为'UserDBModel.Store.UserProfile'.
我正在尝试使用 DBExecutionStrategy 重试已超时的查询,但是当超时发生时,我收到错误“SqlParameter 已包含在另一个 SqlParameterCollection 中”。我正在使用 EF6。
我的查询:
using (var ctx = new EntityModel())
{
IEnumerable<ItemResponse> items= ctx.Database.SqlQuery<ItemResponse>(
"spItemListGet @UserID", new SqlParameter("@UserID", UserID)
).ToList();
}
Run Code Online (Sandbox Code Playgroud)
我的执行策略:
protected override bool ShouldRetryOn(Exception ex)
{
bool retry = false;
SqlException sqlException = ex as SqlException;
if (sqlException != null)
{
int[] errorsToRetry =
{
-2, //Timeout
};
if (sqlException.Errors.Cast<SqlError>().Any(x => errorsToRetry.Contains(x.Number)))
{
retry = true;
}
else
{
throw ex; //dont retry
}
}
return retry;
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
System.ArgumentException: The SqlParameter is already …Run Code Online (Sandbox Code Playgroud) c# ×3
sql-server ×2
ado.net ×1
asp.net ×1
asp.net-mvc ×1
disk ×1
regex ×1
sql ×1
t-sql ×1
validation ×1
web-services ×1
windows ×1
windows-8 ×1