I have a sql server with the table "contacts", in this table i have column "clicks" of type int, i want to increment its value without making a query.
This is a copy of: "Entity framework update one column by increasing the current value by one without select" the solution that suggested there is using EntityFramework.Utilities the problem is that its not a IQueryable extension like EntityFramework.Extended and that makes it hard to implement for me.
the question is there any other way/solution to incremenet int value on sql with using IQueryable(without actually writing sql query)?
the result of the IQueryable query should look like:
UPDATE Contacts SET clicks=clicks+1 WHERE id=8432
I just found the solution after some research and testing, actually EntityFramework.Extended do exactly what i want it to do, if you want to increment a column just call the Update method with adding assignment:
db.Contacts.Where(c => c.Id == id).Update(c => new Contact { Clicks = c.Clicks + 1 });
After checking the source code of EntityFramework.Extended and debugging it i saw that the query that executed in the end is exactly what i wanted, so thanks everybody for trying to help, the solution were right under my nose ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With