我需要在数据库中首先选择(比方说)10000行并返回它们.可能有更多客户端同时执行此操作.我提出了这个问题:
update v set v.batch_Id = :batchId
from tblRedir v
inner join (
select top 10000 id
from tblRedir
where batch_Id is null
order by Date asc
) v2 on v.id=v2.id
Run Code Online (Sandbox Code Playgroud)
它是一个由更新和嵌套选择组成的操作.两个查询都在同一个表(tblRedir)上工作.这个想法是行首先由唯一的batchId标记,然后通过返回
select * from tblRedir where batch_id = :batchId
Run Code Online (Sandbox Code Playgroud)
(batchid是每个此更新的唯一标识符(例如,时间戳或guid))
我的问题:
我认为嵌套select的操作更新是原子的 - 这意味着每个客户端都会收到他自己的唯一数据集(没有其他客户端收到他的数据子集).
但是它看起来是我错了-在某些情况下是没有收到数据的客户,因为他们很可能首先都执行选择和那么这两个执行更新(所以第一个客户端没有明显的行).
这个操作是原子的吗?
我使用Sql server 2005.查询是通过NHibernate运行的
session.CreateSQLQuery('update....')
Run Code Online (Sandbox Code Playgroud) 一般代码
考虑以下代码:
PS> function Test { param($p='default value') $PsBoundParameters }
PS> Test 'some value'
Key Value
--- -----
p some value
PS> Test
# nothing
Run Code Online (Sandbox Code Playgroud)
我希望在两种情况下$PsBoundParameters都包含$p变量记录.这是正确的行为吗?
题
我想使用这样的splatting来实现很多功能:
function SomeFuncWithManyRequiredParams {
param(
[Parameter(Mandatory=$true)][string]$p1,
[Parameter(Mandatory=$true)][string]$p2,
[Parameter(Mandatory=$true)][string]$p3,
...other parameters
)
...
}
function SimplifiedFuncWithDefaultValues {
param(
[Parameter(Mandatory=$false)][string]$p1='default for p1',
[Parameter(Mandatory=$false)][string]$p2='default for p2',
[Parameter(Mandatory=$false)][string]$p3='default for p3',
...other parameters
)
SomeFuncWithManyRequiredParams @PsBoundParameters
}
Run Code Online (Sandbox Code Playgroud)
我不想用枚举的所有参数调用SomeFuncWithManyRequiredParams:
SomeFuncWithManyRequiredParams -p1 $p1 -p2 $p2 -p3 $p3 ...
Run Code Online (Sandbox Code Playgroud)
可能吗?
我们希望将我们的项目从ASP.NET MVC 2升级到3.我们的大多数测试都成功了,但有些测试失败了ValueProviderFactories.Factories.GetValueProvider(context).
这是一个简单的测试类,用于解决问题.
[TestFixture]
public class FailingTest
{
[Test]
public void Test()
{
var type = typeof(string);
// any controller
AuthenticationController c = new AuthenticationController();
var httpContext = new Mock<HttpContextBase>();
var context = c.ControllerContext = new ControllerContext(httpContext.Object, new RouteData(), c);
IModelBinder converter = ModelBinders.Binders.GetBinder(type);
var bc = new ModelBindingContext
{
ModelName = "testparam",
ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, type),
ValueProvider = ValueProviderFactories.Factories.GetValueProvider(context)
};
Console.WriteLine(converter.BindModel(context, bc));
}
}
Run Code Online (Sandbox Code Playgroud)
异常"对象引用未设置为对象的实例." ValueProviderFactories.Factories.GetValueProvider(context)被叫时被抛出.stacktrace看起来像这样:
Microsoft.Web.Infrastructure.dll!Microsoft.Web.Infrastructure.DynamicValidationHelper.ValidationUtility.CollectionReplacer.GetUnvalidatedCollections(System.Web.HttpContext context) + 0x23 bytes
Microsoft.Web.Infrastructure.dll!Microsoft.Web.Infrastructure.DynamicValidationHelper.ValidationUtility.GetUnvalidatedCollections(System.Web.HttpContext context, out System.Collections.Specialized.NameValueCollection …Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
PS> $timer = New-Object Timers.Timer
PS> $timer.Interval = 1000
PS> $i = 1;
PS> Register-ObjectEvent $timer Elapsed -Action { write-host 'i: ' $i }.GetNewClosure()
PS> $timer.Enabled = 1
i: 1
i: 1
i: 1
...
# wait a couple of seconds and change $i
PS> $i = 2
i: 2
i: 2
i: 2
Run Code Online (Sandbox Code Playgroud)
我假设当我创建新的closure({ write-host 'i: ' $i }.GetNewClosure())值时$i将绑定到此闭包.但不是在这种情况下.我改变了值,write-host取新值.
另一方面,这有效:
PS> $i = 1;
PS> $action = { write-host 'i: ' $i …Run Code Online (Sandbox Code Playgroud) 如果我不需要从0开始,如何找到子串的正确方法是什么?
我有这个代码:
fn SplitFile(reader: BufReader<File>) {
for line in reader.lines() {
let mut l = line.unwrap();
// l contains "06:31:53.012 index0:2015-01-06 00:00:13.084
...
Run Code Online (Sandbox Code Playgroud)
我需要找到第三个:并解析它背后的日期.仍然不知道该怎么做,因为find没有任何类似的参数begin- 请参阅https://doc.rust-lang.org/std/string/struct.String.html#method.find.
(我知道我可以使用正则表达式.我已经完成了,但我想比较性能 - 手动解析是否比使用正则表达式更快.)
我想在bobril中用鼠标移动一个SVG元素(圆圈).我应该使用哪种生命周期组件方法?我尝试使用onPointerDown等等,但这些方法只处理圆圈内的事件.我应该使用拖放还是有其他选项来围绕整个SVG移动圆圈?
我的同事告诉我,基于表格的代码格式很糟糕,而且没有可读性,我应该遵循惯例.基于表格的格式有什么不好?为什么禁止它?
我问,因为对我来说它更具可读性.
示例(不是真实代码):
if (res == ResultType.Failure)
something = ProcessFailure(..);
if (res == ResultType.ScheduledAndMonitored)
something = DoSomething(...) && DoSomething3(..);
if (res == ResultType.MoreInfoAvailable)
info = GetInfo(..);
if (res == ResultType.OK && someCondition)
something = DoSomething2(..);
.... continued
Run Code Online (Sandbox Code Playgroud)
与
if (res == ResultType.Failure) something = ProcessFailure(..);
if (res == ResultType.ScheduledAndMonitored) something = DoSomething(...) && DoSomething3(..);
if (res == ResultType.MoreInfoAvailable) info = GetInfo(..);
if (res == ResultType.OK && someCondition) something = DoSomething2(..);
.... continued
Run Code Online (Sandbox Code Playgroud)
为什么我认为第二个更好:
我希望能够将Windows中的剪贴板上的文本发送到应用程序.例如,我正在编写记事本中的文本文件,我想将一部分复制到一个新文件中..我想将其复制到剪贴板,然后使用热键启动发送的应用程序或powershell脚本将文本复制到记事本的新实例.
我怎样才能在C#或Powershell中实现这一目标?
解决方案:使用AutoHotKey
^+c::
Send ^c
Run Notepad
WinWait Untitled - Notepad
WinActivate
Send ^v
return
Run Code Online (Sandbox Code Playgroud) 我试图找到一个关于如何使用的例子TryScan,但没有找到任何,你能帮助我吗?
我想做什么(非常简单的例子):我有一个MailboxProcessor接受两种类型的消息.
第一个GetState返回当前状态.
GetState消息经常发送
另一个UpdateState非常昂贵(耗时) - 例如从互联网下载某些内容然后相应地更新状态.
UpdateState被称为很少.
我的问题是 - 消息GetState被阻止并等到前面UpdateState服务.这就是为什么我试图用来TryScan处理所有GetState消息,但没有运气.
我的示例代码:
type Msg = GetState of AsyncReplyChannel<int> | UpdateState
let mbox = MailboxProcessor.Start(fun mbox ->
let rec loop state = async {
// this TryScan doesn't work as expected
// it should process GetState messages and then continue
mbox.TryScan(fun m ->
match m with
| GetState(chnl) ->
printfn "G processing TryScan" …Run Code Online (Sandbox Code Playgroud) powershell ×3
c# ×2
concurrency ×2
rust ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
autohotkey ×1
automation ×1
bobril ×1
clipboard ×1
closures ×1
coding-style ×1
events ×1
f# ×1
function ×1
httpcontext ×1
javascript ×1
messages ×1
nhibernate ×1
parameters ×1
sql ×1
sql-server ×1
svg ×1
typescript ×1
unit-testing ×1