由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - How to lock tabel with LINQ to SQL (转载)
相关主题
求助:如何ColumName 作为变量放入query请教一个SQL Server的面试题
SQL copy a table into a new table and add a new columnAccess 里面两个 column不一样的table 能combine 到一起吗?
mysql mapping and insert questionsort two same tables SQL but different results
紧急求助, 关于SQL Server请教一个sql问题
SQL add some columns into a table from another table (转载Re: [转载] JDBC用完了oracle的large pool (memor
error of executing SQL query of string concatenation (转载一个关于Oracle Archivelog mode的问题
怎样解决 Index for NULL value有谁用SQL Server的DTS package连过Teradata吗?
菜鸟问题,急SQL Server 2005 Exec( )
相关话题的讨论汇总
话题: linq话题: seqno话题: sql话题: lock话题: col1
进入Database版参与讨论
1 (共1页)
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.

1 (共1页)
进入Database版参与讨论
相关主题
SQL Server 2005 Exec( )SQL add some columns into a table from another table (转载
改写(migrate) stored proc 问题error of executing SQL query of string concatenation (转载
MS SQL 2008 column permissions怎样解决 Index for NULL value
How to split a column into several rows?菜鸟问题,急
求助:如何ColumName 作为变量放入query请教一个SQL Server的面试题
SQL copy a table into a new table and add a new columnAccess 里面两个 column不一样的table 能combine 到一起吗?
mysql mapping and insert questionsort two same tables SQL but different results
紧急求助, 关于SQL Server请教一个sql问题
相关话题的讨论汇总
话题: linq话题: seqno话题: sql话题: lock话题: col1