I have a table that have many 1:1 relation define (see bottom)
On my service side I call Db.Save(audit, true);
When I try to assign more then one reference I got the exception:
ServiceStack.WebServiceException : Exception of type ‘ServiceStack.Data.OptimisticConcurrencyException’
When I query my table from SSMS I see my result in Audit, ManureResult and RumenFillResult
Why I have a concurrency issue my 3 records are new so the Save should not try to validate rowversion property ?
My assignment:
var fr = new FarmsRequest();
var frResponse = client.Get(fr);
var request = new SyncAuditRequest();
var audit = new Audit();
audit.Name = "FakeSync";
audit.FlatStage = "FakeSync";
audit.MainType = "FakeSync";
audit.AnimalNb = "200";
audit.AnimalAge = "9";
audit.AnimalSex = "male";
audit.AnimalDietType = "Normal";
audit.Date = System.DateTime.UtcNow;
audit.State = "Fine";
audit.Progress = 60;
audit.Score = "60";
audit.Benchmark = "FakeTest";
audit.FarmId = frResponse.Farms[0].FarmId;
//var dietResult = new DietResult();
//dietResult.AccessFiber = 15;
//dietResult.MainFiber = 12;
//dietResult.FiberQuality = 20;
//dietResult.FiberRegularity = 35;
//dietResult.ValidCategory = true;
//audit.DietResult = dietResult;
var manureResult = new ManureResult();
manureResult.Medium = "5";
manureResult.Pasty = "3";
manureResult.Liquid = "0";
audit.ManureResult = manureResult;
var rumenFillResult = new RumenFillResult();
rumenFillResult.Normal = "10";
rumenFillResult.SlightlyEmpty = "1";
rumenFillResult.Bloated = "2";
audit.RumenFillResult = rumenFillResult;
request.Audit = audit;
var response = client.Post(request);
My definition Poco:
[Schema("REIBeef")] //Specifique to REIBeef
public class Audit : AuditBOFields, IAudit, IConcurrency
{
[PrimaryKey,AutoIncrement]
public int? AuditId { get; set; }
public string Name { get; set; }
public string FlatStage { get; set; }
public string MainType { get; set; }
public string AnimalNb { get; set; }
public string AnimalAge { get; set; }
public string AnimalSex { get; set; }
public string AnimalDietType { get; set; }
public DateTime Date { get; set; }
public string State { get; set; }
public double Progress { get; set; }
public string Score { get; set; }
public string Benchmark { get; set; }
public string Vignet { get; set; }
public string Comment { get; set; }
[References(typeof(Farm)),]
public int? FarmId { get; set; }
[Reference]
public Farm Farm { get; set; }
[References(typeof(DietResult))]
public int? DietId { get; set; }
[Reference]
public DietResult DietResult { get; set; }
[References(typeof(ManureResult))]
public int? ManureId { get; set; }
[Reference]
public ManureResult ManureResult { get; set; }
[References(typeof(RumenFillResult))]
public int? RumenId { get; set; }
[Reference]
public RumenFillResult RumenFillResult { get; set; }
[References(typeof(FacilitiesResult))]
public int? FacilityId { get; set; }
[Reference]
public FacilitiesResult FacilitiesResult { get; set; }
[References(typeof(CleanlinessResult))]
public int? CleanId { get; set; }
[Reference]
public CleanlinessResult CleanlinessResult { get; set; }
[References(typeof(FeetInflamationResult))]
public int? FeetId { get; set; }
[Reference]
public FeetInflamationResult FeetInflamationResult { get; set; }
[References(typeof(HornsInflamationResult))]
public int? HornsInflamationRowId { get; set; }
[Reference]
public HornsInflamationResult HornsInflamationResult { get; set; }
[References(typeof(AnimalPerformanceResult))]
public int? ApId { get; set; }
[Reference]
public AnimalPerformanceResult AnimalPerformanceResult { get; set; }
[References(typeof(TemperaturehumidityResult))]
public int? TempId { get; set; }
[Reference]
public TemperaturehumidityResult TemperaturehumidityResult { get; set; }
[References(typeof(BehaviourObservationsResult1))]
public int? Bo1Id { get; set; }
[Reference]
public BehaviourObservationsResult1 BehaviourObservationsResult1 { get; set; }
[References(typeof(BehaviourObservationsResult2))]
public int? Bo2Id { get; set; }
[Reference]
public BehaviourObservationsResult2 BehaviourObservationsResult2 { get; set; }
public ulong RowVersion { get; set; }
}
}