Following this question, I tried to convert a sequence of try..Insert()..catch..Update() into a single call to Save(). I'm getting StaleStateException with "Unexpected row count: 0; expected: 1".
What am I doing wrong?
Here is the code that fails:
var u = new User {SignupDate = DateTime.Now, Name="Foo", OpenId = "Bar"};
ActiveRecordMediator<User>.Save(u);
var q = new Question
{
Author = u,
Body = "",
CreatedDate = DateTime.Now,
LastRelatedUser = u,
Title = "",
UpdateDate = DateTime.Now
};
ActiveRecordMediator<Question>.Save(q);
var v = new VoteOnQuestion {Key = new VoteKey(u.Id, q.Id)};
// This fails with StaleStateException
ActiveRecordMediator<VoteOnQuestion>.Save(v);
VoteOnQuestion class simply inherits from VoteOnPost, which looks like this:
public abstract class VoteOnPost
{
[CompositeKey]
public VoteKey Key { get; set; }
[Property]
public VoteType Vote { get; set; }
}