given table, example article(id,body,revisions), increment revisions attribute, and, once limit reached (it's constant provided developer), error should thrown. possible achieve single update ... set statement in t-sql?
what i've done:
- to increment revisions attribute one, solved shown here: is update command thread safe (tracking revisions) in ms sql.
problem
- to find way thread safe, allow incrementation of revisions until upper bound reached.
context
since i'm using ef, ideal solution either thrown error or specify flag of sort. code i'm using (shown below) encapsulated try-catch:
context.database.executesqlcommand("update dbo.articles set revisions = revisions + 1 id=@p0;", articleid);
you where
clause in update
statement, test. if test fails, update not happen , call context.database.executesqlcommand
return 0 instead of 1.
in case of limit of 1000, update sql be:
count = context.database.executesqlcommand( "update dbo.articles set revisions = revisions + 1 id=@p0 , revisions < 1000;", articleid);
then afterwards test whether count == 0
, raise error message if so.
Comments
Post a Comment