WCF与REST和SOAP之间有什么关系?WCF是基于这些技术之一(REST还是SOAP)还是单独的技术?
我想知道多个.Where()语句是否存在性能影响.例如我可以写:
var contracts = Context.Contract
.Where(
c1 =>
c1.EmployeeId == employeeId
)
.Where(
c1 =>
!Context.Contract.Any(
c2 =>
c2.EmployeeId == employeeId
&& c1.StoreId == c2.StoreId
&& SqlFunctions.DateDiff("day", c2.TerminationDate.Value, c1.DateOfHire.Value) == 1
)
)
.Where(
c1 =>
!Context.EmployeeTask.Any(
t =>
t.ContractId == c1.Id
)
);
Run Code Online (Sandbox Code Playgroud)
或者我可以将它们全部组合到一个Where()子句中,如下所示:
var contracts = Context.Contract
.Where(
c1 =>
c1.EmployeeId == employeeId
&& !Context.Contract.Any(
c2 =>
c2.EmployeeId == employeeId
&& c1.StoreId == c2.StoreId
&& SqlFunctions.DateDiff("day", c2.TerminationDate.Value, c1.DateOfHire.Value) == 1
)
&& !Context.Employee_Task.Any(
t =>
t.ContractId == c1.Id …Run Code Online (Sandbox Code Playgroud) 我已经使用Visual Studio 2012将我的asp.net 2.0项目升级到4.5.它构建正常,但是我必须在浏览器中测试每个webform还是100%自动转换?如果没有.Net Framework 2.0,转换后的项目是否可以正常工作?
我使用以下PHP代码来计算BPay的CRN:
<?php
function LuhnCalc($number) {
$chars = array_reverse(str_split($number, 1));
$odd = array_intersect_key($chars, array_fill_keys(range(1, count($chars), 2), null));
$even = array_intersect_key($chars, array_fill_keys(range(0, count($chars), 2), null));
$even = array_map(function($n) { return ($n >= 5)?2 * $n - 9:2 * $n; }, $even);
$total = array_sum($odd) + array_sum($even);
return ((floor($total / 10) + 1) * 10 - $total) % 10;
}
print LuhnCalc($_GET['num']);
?>
Run Code Online (Sandbox Code Playgroud)
然而,似乎BPAY是MOD 10的第5版,我找不到任何文档.它似乎与MOD10不一样.
测试的以下数字:
2005,1597,3651,0584,9675
bPAY
2005 = 20052
1597 = 15976
3651 = 36514
0584 = 05840
9675 = 96752 …Run Code Online (Sandbox Code Playgroud) 我正在尝试从WebApi v2(完整框架,而不是点网核心)中的snake_cased JSON绑定我的PascalCased c#模型。
这是我的API:
public class MyApi : ApiController
{
[HttpPost]
public IHttpActionResult DoSomething([FromBody]InputObjectDTO inputObject)
{
database.InsertData(inputObject.FullName, inputObject.TotalPrice)
return Ok();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的输入对象:
public class InputObjectDTO
{
public string FullName { get; set; }
public int TotalPrice { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
我的问题是JSON看起来像这样:
{
"full_name": "John Smith",
"total_price": "20.00"
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用JsonProperty属性:
public class InputObjectDTO
{
[JsonProperty(PropertyName = "full_name")]
public string FullName { get; set; }
[JsonProperty(PropertyName = "total_price")]
public int TotalPrice { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是我的InputObjectDTO 很大 …
我正在尝试使用ValueInjector来压缩一个类,并让它同时复制值Nullable<int>'s到int的.
例如,给出以下(人为)课程:
class CustomerObject
{
public int CustomerID { get; set; }
public string CustomerName { get; set; }
public OrderObject OrderOne { get; set; }
}
class OrderObject
{
public int OrderID { get; set; }
public string OrderName { get; set; }
}
class CustomerDTO
{
public int? CustomerID { get; set; }
public string CustomerName { get; set; }
public int? OrderOneOrderID { get; set; }
public string OrderOneOrderName { get; set; } …Run Code Online (Sandbox Code Playgroud) 标记为异步的功能是否有任何副作用,但实际上并未进行任何等待调用?例如:
public interface IMyInterface
{
Task DoSomethingAsync();
}
public class DoSomething1:IMyInterface
{
public async Task DoSomethingAsync()
{
await getSomethingFromDatabaseAsync();
}
}
public class DoSomething2:IMyInterface
{
public async Task DoSomethingAsync()
{
doSomethingElse();
}
}
Run Code Online (Sandbox Code Playgroud)
IMyInterface由许多类实现,但是对于其中一个类,没有等待调用。这会引起任何问题吗?
使用 Parallel.ForEach 时,将任何 DB 或 Api 调用转换为异步方法是否会提高性能?
一些背景知识,我目前有一个控制台应用程序,它按顺序循环访问一堆文件,并为每个文件调用一个 API 并进行一些数据库调用。主要逻辑如下:
foreach (file in files)
{
ReadTheFileAndComputeAFewThings(file);
CallAWebService(file);
MakeAFewDbCalls(file);
}
Run Code Online (Sandbox Code Playgroud)
目前,所有数据库和 Web 服务调用都是同步的。
Parallel.ForEach正如您所期望的那样,更改要使用的循环给我带来了巨大的性能提升。
我想知道是否将调用保留Parallel.ForEach在那里,并在循环内将所有 Web 服务调用更改为异步(例如,HttpClient.SendAsync)并将 DB 调用更改为异步(使用 Dapper,db.ExecuteAsync()) - 这是否会通过允许它来提高应用程序的性能重用线程?或者它实际上什么都不做,因为Parallel.ForEach无论如何都会处理线程分配?
调用 API 时出现以下异常:
InvalidOperationException - The current type, System.Collections.Generic.IReadOnlyDictionary`2[System.Type,Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsExtension], is an interface and cannot be constructed. Are you missing a type mapping?
这是完整的错误:
{
"Message": "An error has occurred.",
"ExceptionMessage": "An error occurred when trying to create a controller of type 'TechnicianController'. Make sure that the controller has a parameterless public constructor.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": " at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Resolution of the dependency …Run Code Online (Sandbox Code Playgroud) 我正在创建一个网页,其中包含不同类型文本的混合 - 粗体,下划线,小,左对齐,居中对齐,右对齐等,并尝试从HTML中抽象样式,我我试图取消<b>和<u>标记.结果是定义类(例如"粗体","下划线","小"等)并使用CSS来提供样式.但是,这使得HTML更加冗长,div和span都有类似的东西class="rightAlign small bold underline".有一个更好的方法吗?
谢谢!
c# ×5
.net ×1
asp.net ×1
async-await ×1
automapper ×1
clause ×1
credit-card ×1
css ×1
dapper ×1
html ×1
httpclient ×1
json.net ×1
linq ×1
luhn ×1
payment ×1
performance ×1
php ×1
rest ×1
soap ×1
task ×1
wcf ×1
web-services ×1
where ×1