f*****e 发帖数: 5177 | 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 | B*****g 发帖数: 34098 | 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, ...
| s**m 发帖数: 1564 | 3 Can Rank() or Row_Number() etc help? I don't know if and how they can be
expressed in LINQ | B*****g 发帖数: 34098 | 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
| s**m 发帖数: 1564 | 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 | t****n 发帖数: 263 | 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, ...
| B*****g 发帖数: 34098 | 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.
| t****n 发帖数: 263 | 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.
| B*****g 发帖数: 34098 | 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.
|
|