Let' say I have a TestClass in my C# app with property A and property B. I change the value of B by my code, I leave property A unchanged. I update TestClass in database by SimpleRepository's Update method.
As I see it updates also property A value in the database.
It is easy to test: I change value A in my database outside my app ('by hand'), then I make the update from my app. Value of property A changes back to its value according to TestClass's state in my app.
So, my question: is it possible to make updates only to some properties, not for the whole class by SimpleRepository? Are there some 'IgnoreFields' possibilities?
What you need is
optimistic concurrency
on yourUPDATE
statement, not to exclude certain fields. In short what that means is when updating a table, aWHERE
clause is appended to yourUPDATE
statement that ensures the values of the fields in the row are in fact what they were when the lastSELECT
was run.So, let's assume in your example I selected some data and the values for
A
andB
were1
and2
respectively. Now let's assume I wanted to updateB
(below statement is just an example):However, instead of running that statement (because there's no concurrency there), let's run this one:
That statement now ensures the record hasn't been changed by anybody.
However, at the moment it doesn't appear that Subsonic's SimpleRepository supports any type of concurrency and so that's going to be a major downfall. If you're looking for a very straight forward repository library, where you can use POCO's, I would recommend Dapper. In fact, Dapper is used by Stackoverflow. It's extremely fast and will easily allow you to build in concurrency into your update statements because you send down parameterized SQL statements, simple.
NOTE: with Dapper you could actually do what you're wanting to as well because you send down basic SQL statements, but I just wouldn't recommend not using concurrency.