I have a problem inserting data into the table after deleting data. It works the first time or if I restart the app then it works.
public class SingleTestCycle
{
public virtual int Id { get; protected set; }
public virtual int OpeningTime { get; set; }
...
public virtual CompleteOneTest CompleteOneTest { get; set; }
}
public class CompleteOneTest
{
public virtual int Id { get; protected set; }
public virtual string StartTime { get; set; }
public virtual string EndTime { get; set; }
public virtual IList<SingleTestCycle> SingleTest { get; set; }
Mappings are like as follows:
public class SingleTestCycleMap : ClassMap<SingleTestCycle>
{
public SingleTestCycleMap()
{
Id(x => x.Id);
Map(x => x.DoorOpeningTime);
Map(x => x.DoorClosingTime);
Map(x => x.FlowValveOpeningTime);
Map(x => x.FlowValveClosingTime);
References(x => x.CompleteOneTest);
}
}
public class CompleteOneTestMap : ClassMap<CompleteOneTest>
{
public CompleteOneTestMap()
{
Id(x => x.Id);
Map(x => x.StartTime);
Map(x => x.EndTime);
HasMany(x => x.SingleTest)
.Inverse()
.Cascade.All();
}
}
Trying to delete it in the following way.
I get the following error:
System.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK2B1FA9F15AE67907". The conflict occurred in database "MTScada", table "dbo.CompleteOneTest", column 'Id'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
sp_help shows there is PK__Complete__3214EC07E08D05D2 in the management studio.
I tried to delete by the following way but did not help
ExecuteSQLQuery("DELETE FROM SingleTestCycle WHERE [CompleteOneTest_id]=" + "'" + item + "'");
Thread.Sleep(200);
ExecuteSQLQuery("DELETE FROM CompleteOneTest WHERE Id=" + "'" + item + "'");
User contributions licensed under CC BY-SA 3.0