简体   繁体   English

使用实体框架增加一列值

[英]Increase one column value using Entity Framework

I have a column named Order - Int in a table. 我在表中有一列名为Order - Int的列。 I'm using Entity Framework. 我正在使用实体框架。 I need to Increase a value when I insert a row. 当我插入一行时,我需要增加一个值。 ie

Order 
1 
2 
3 
4

When I insert a row with order 2 then all the columns greater than 1 has to increase by one so that 当我插入顺序为2的行时,所有大于1的列都必须增加一,以便

Order 
1 
2 (New) 
3 
4 
5

And the same has to be reversed when I delete the row with order 2. Also consider on updating case. 当我删除订单2的行时,必须颠倒同样的情况。也要考虑更新大小写。

Is there an efficient way to achieve this? 有没有有效的方法来实现这一目标?

I'm not sure about EF, unless to use direct SQL Command execution, but in SQL you can do this way: 我不确定EF,除非使用直接SQL命令执行,但是在SQL中,您可以这样做:

DBCC CHECKIDENT (mytable, RESEED, 0)

I believe it's better way to use trigger for this purpose, instead of C# code. 我相信这是使用触发器而不是C#代码的更好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM