asp.net mvc - Stub Update an Entity in Entity Framework -


i want update entity property(count) in entity framework 6 stub update manner, indeed want plus 1 count property value without query database. how can this?

      //...       var stub = new entity {id = id};       _articles.attach(stub);        stub.count++; // count 1! how can without fetch/query database?       context.savechanges();       //... 

the way i'm aware of use stored procedure.

create proc sp_updatecount @id int update [dbo].[entitytable] set [count] = [count] + 1 [id] = @id  

and run in code

sqlparameter paramid = new sqlparameter("@id", id); context.database.executesqlcommand("sp_updatecount @id", paramid); 

please note run procedure , don't have call savechanges it. if want execute procedure in transaction other changes make sure create 1 explicitly transactionscope.

hope helps!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -