This question is locked. New answers and comments are not allowed.
Let's assume REST service scenario (MVC) with Domain model & context, and MS SQL table like
CREATE TABLE Leagues (
LeagueId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
LeagueName nvarchar(512) NOT NULL,
StateProvince varchar(3) NOT NULL,
CountryCode varchar(3) NOT NULL,
RV timestamp NOT NULL
)
// LeagueController.cs
public class LeagueController : Controller {
DataContext dc = null;
public LeagueController() {
dc = new DerbyContext();
}
// ...
// UPDATE - works perfectly: "... WHERE [LeagueId] = ? AND [RV] = ?"
[HttpPost]
public ActionResult Edit(int id, FormCollection collection) {
League league = new League() {
LeagueId = id,
LeagueName = String.IsNullOrEmpty(collection["LeagueName"]) ? null : collection["LeagueName"],
StateProvince = String.IsNullOrEmpty(collection["StateProvince"]) ? null : collection["StateProvince"],
CountryCode = String.IsNullOrEmpty(collection["CountryCode"]) ? null : collection["CountryCode"],
RV = Int64.Parse(collection["RV"])
};
league = dc.AttachCopy<League>(league);
dc.SaveChanges();
// ...
}
// DELETE - does NOT take RV field into account: "... WHERE [LeagueId] = ?"
[HttpPost]
public ActionResult Delete(int id, FormCollection collection) {
League league = new League() {
LeagueId = id,
RV = Int64.Parse(collection["RV"])
};
league = dc.AttachCopy<League>(league);
dc.Delete(league);
dc.SaveChanges();
//...
}
and the record gets deleted despite it has been modified in another app
CREATE TABLE Leagues (
LeagueId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
LeagueName nvarchar(512) NOT NULL,
StateProvince varchar(3) NOT NULL,
CountryCode varchar(3) NOT NULL,
RV timestamp NOT NULL
)
// LeagueController.cs
public class LeagueController : Controller {
DataContext dc = null;
public LeagueController() {
dc = new DerbyContext();
}
// ...
// UPDATE - works perfectly: "... WHERE [LeagueId] = ? AND [RV] = ?"
[HttpPost]
public ActionResult Edit(int id, FormCollection collection) {
League league = new League() {
LeagueId = id,
LeagueName = String.IsNullOrEmpty(collection["LeagueName"]) ? null : collection["LeagueName"],
StateProvince = String.IsNullOrEmpty(collection["StateProvince"]) ? null : collection["StateProvince"],
CountryCode = String.IsNullOrEmpty(collection["CountryCode"]) ? null : collection["CountryCode"],
RV = Int64.Parse(collection["RV"])
};
league = dc.AttachCopy<League>(league);
dc.SaveChanges();
// ...
}
// DELETE - does NOT take RV field into account: "... WHERE [LeagueId] = ?"
[HttpPost]
public ActionResult Delete(int id, FormCollection collection) {
League league = new League() {
LeagueId = id,
RV = Int64.Parse(collection["RV"])
};
league = dc.AttachCopy<League>(league);
dc.Delete(league);
dc.SaveChanges();
//...
}
and the record gets deleted despite it has been modified in another app