更新选择在LINQ to SQL [英] UPDATE SELECT in LINQ to SQL
本文介绍了更新选择在LINQ to SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写一个多线程服务,拿起作业过程中,有1(未处理)状态。一旦他们被拾起,我需要那些行的状态更改为2(表示正在进行中),这样另一个线程(即在几秒钟内生成)不拿起这些行进行处理。
I am writing a multithreaded service that picks up jobs to process that has the status of 1 (unprocessed). As soon as they are picked up, I need to change the status of those rows to 2 (indicates In Progress) so that another thread (that is spawned within a few seconds) does not pick up these rows for processing.
有关选择,我会做这样的事情:
For select, I would do something like this:
var jobs = from j in db.Jobs
where j.Status == 1
select j;
我如何重写这个更新行,并选择它们在同一时间?
How do I rewrite this to update the rows and also select them at the same time?
推荐答案
Use a transaction. There are some examples of how it works here.
这篇关于更新选择在LINQ to SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文