[英]Devart dotconnect - Is there a way to force the commit order?
I am using devart dotconnect for Oracle v7.7, and am getting a unexpected error. 我正在将devart dotconnect用于Oracle v7.7,并且遇到了意外错误。 I am inserting a record into table A, and then another a number of records into table B where B has a foreign key to A, and I'm getting a parent key not found error.
我正在向表A中插入一条记录,然后向表B中再插入一些记录,其中B具有到A的外键,而我得到的是未找到父键的错误。
SsinpatDataContext dc = new SsinpatDataContext();
Document doc = new Document();
doc.Text = "bla bla bla";
var id = dc.ExecuteQuery<decimal>("SELECT DOCUMENT_SEQ.NEXTVAL FROM DUAL");
doc.Id = id.ElementAt(0);
dc.Documents.InsertOnSubmit(doc);
DocumentRows dr = new DocumentRows();
dr.Text = "bla bla bla";
dr.DocId = doc.Id;
dc.DocumentRows.InsertOnSubmit(dr);
dc.SubmitChanges();
this throws an exception with the text "ORA-02291: integrity constraint violated-parent key not found" It seems to me that devart is trying to commit the DocumentRows object first, and only then the Document object... 这将引发文本异常“ ORA-02291:违反完整性约束-找不到父键”在我看来,devart尝试首先提交DocumentRows对象,然后才提交Document对象。
Now, my question here is whether there is a way we can force the commit execution order. 现在,我的问题是是否有一种方法可以强制执行提交命令。
Thanks. 谢谢。
The issue probably is that the IdGenerator is set to Sequence for the Id property of the entity class Document in your model. 问题可能是您的模型中实体类Document的Id属性的IdGenerator设置为Sequence。 And, due to the fact that you are performing this query in your code
而且,由于您正在代码中执行此查询
"SELECT DOCUMENT_SEQ.NEXTVAL FROM DUAL"
the next sequence value is queried twice and the discrepancy is the last value of the sequence occurs. 下一个序列值被查询两次,并且差异是该序列的最后一个值。 You can check it via logging:
您可以通过记录来检查它:
SsinpatDataContext dc = new SsinpatDataContext(){Log=Console.Out};
To avoid this error in your scenario, you should set the IdGenerator to None for the Id property of the entity class Document and re-generate the code for your model. 为避免在您的方案中发生此错误,应将实体类Document的Id属性的IdGenerator设置为None,并重新生成模型的代码。
However, the better scenario would be the following: 但是,更好的情况如下:
1) set the IdGenerator to Sequence for the Id property of the entity class Document; 1)将实体类Document的Id属性的IdGenerator设置为Sequence; specify the name of the sequence, in your case - DOCUMENT_SEQ;
在您的情况下,指定序列的名称-DOCUMENT_SEQ;
2) re-write you code: 2)重新编写您的代码:
SsinpatDataContext dc = new SsinpatDataContext(){Log=Console.Out};
Document doc = new Document();
doc.Text = "bla bla bla";
DocumentRows dr = new DocumentRows();
dr.Text = "bla bla bla";
dr.Doc = doc;
dc.Documents.InsertOnSubmit(doc);
dc.SubmitChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.