Redian新闻
>
How to lock tabel with LINQ to SQL (转载)
avatar
How to lock tabel with LINQ to SQL (转载)# Database - 数据库
f*e
1
【 以下文字转载自 DotNet 讨论区 】
发信人: flyfire (flyfire), 信区: DotNet
标 题: How to lock tabel with LINQ to SQL
发信站: BBS 未名空间站 (Mon Feb 16 23:56:26 2009)
Here is the table:
Col1, Seqno, ...
A, 1, ...
A, 2, ...
A, 3, ...
B, 1, ...
C, 1, ...
(Col1 + seqno) is the primary key.
When I use LINQ to insert a new record, I need to calculate next seqno. For
example, if I want to insert a new row with value A in col1, the seqno will
be 4.
It is not hard to do the calculation. But the problem is that I need to lock
the
avatar
B*g
2
linq还不会。
不过你这个一般要用sp或者trigger

【在 f*****e 的大作中提到】
: 【 以下文字转载自 DotNet 讨论区 】
: 发信人: flyfire (flyfire), 信区: DotNet
: 标 题: How to lock tabel with LINQ to SQL
: 发信站: BBS 未名空间站 (Mon Feb 16 23:56:26 2009)
: Here is the table:
: Col1, Seqno, ...
: A, 1, ...
: A, 2, ...
: A, 3, ...
: B, 1, ...

avatar
s*m
3
Can Rank() or Row_Number() etc help? I don't know if and how they can be
expressed in LINQ
avatar
B*g
4
he is asking if multiply insert happen at same time.

【在 s**m 的大作中提到】
: Can Rank() or Row_Number() etc help? I don't know if and how they can be
: expressed in LINQ

avatar
s*m
5
seems can not realize lock while manipulate dataset at client side code. you
can use try catch
try {
db.SubmitChanges();
}
catch (OptimisticConcurrencyException e) {
// You have your choice of RefreshMode to resolve concurrency conflicts.
// You can KeepChanges, KeepCurrentValues, OverwriteCurrentValues.
e.Resolve(RefreshMode.OverwriteCurrentValues);
db.SubmitChanges();
}
let us know if it works. this is a learning process for me too
avatar
t*n
6
This looks like a bad database design to me.
But, anyway, I don't have to maintain this thing.
never used LINQ before. But using SQL, you can do this.
begin tran
select * from TABLE1 with (tablock, updlock, holdlock) where 1=2
then the TABLE1 will be locked until you commit or rollback the transaction.

【在 f*****e 的大作中提到】
: 【 以下文字转载自 DotNet 讨论区 】
: 发信人: flyfire (flyfire), 信区: DotNet
: 标 题: How to lock tabel with LINQ to SQL
: 发信站: BBS 未名空间站 (Mon Feb 16 23:56:26 2009)
: Here is the table:
: Col1, Seqno, ...
: A, 1, ...
: A, 2, ...
: A, 3, ...
: B, 1, ...

avatar
B*g
7
1. insert one record the whole table is locked?
2. does this need more previldges than DML?
明天俺要在oracle里做这件事,头说不care,就让insert fail了得了。

transaction.

【在 t****n 的大作中提到】
: This looks like a bad database design to me.
: But, anyway, I don't have to maintain this thing.
: never used LINQ before. But using SQL, you can do this.
: begin tran
: select * from TABLE1 with (tablock, updlock, holdlock) where 1=2
: then the TABLE1 will be locked until you commit or rollback the transaction.

avatar
t*n
8

don't really understand what do you mean. The way I did it is by query hints
of SQL Server. I don't know a lot about Oracle. I heard 'for update' MAY be
the equivalent.
I don't think so. anyone who can update the table can do it.

【在 B*****g 的大作中提到】
: 1. insert one record the whole table is locked?
: 2. does this need more previldges than DML?
: 明天俺要在oracle里做这件事,头说不care,就让insert fail了得了。
:
: transaction.

avatar
B*g
9
insert 1 record lock the whole table may not be good.

hints
be

【在 t****n 的大作中提到】
:
: don't really understand what do you mean. The way I did it is by query hints
: of SQL Server. I don't know a lot about Oracle. I heard 'for update' MAY be
: the equivalent.
: I don't think so. anyone who can update the table can do it.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。