Linq +删除行时自动减少ID [英] Linq + Auto decrement on id when deleting a row

查看:80
本文介绍了Linq +删除行时自动减少ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的"Work_Table"表中有一个列workid,appid,stepno. Workid是主键.
我的桌子是这样的.

workid appid,stepno
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 2 3
7 2 4
9 2 5
10 3 1
11 3 2

每个appid都有重复的stepno's.好吧,我的问题是,当我通过使用workid删除一个stepno时,stepno的其余部分应该在该appid中自动递减.

例如:如果我删除workid-5,则该appid-2中的stepno将减少,例如1,2,3,4

我想通过使用linq做到这一点.

谁能帮助我.

I have a columns workid,appid,stepno in my table "Work_Table". Workid is primary key.
my table like this.

workid appid , stepno
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 2 3
7 2 4
9 2 5
10 3 1
11 3 2

Every appid has repeated stepno''s. Well my problem is ,when i delete one stepno by using workid, the rest of stepno''s should be auto decrement in that appid.

ex: if i delete workid- 5, then stepno''s in that appid-2 would decrement like 1,2,3,4

I want to do this in by using linq.

Can anyone help me.

推荐答案



尝试以下

Hi,

Try the following

delete from your table name where workid=@workid and stepno=(select max(stepno) from test where workid=@workid)



希望这会有所帮助....



Hope this helps....


这篇关于Linq +删除行时自动减少ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆