简体   繁体   English

Devart dotconnect-有没有办法强制提交顺序?

[英]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.

相关问题 使用devart dotConnect调用Oracle存储过程 - Call Oracle stored procedures using devart dotConnect 如何首先为SQLite代码配置Devart dotConnect? - How Configure Devart dotConnect for SQLite Code First? 无法查询 sqlite 的 devart dotconnect 中的数据 - cannot query for data in devart dotconnect for sqlite 使用Benchmark.NET + DevArt dotConnect for PostgreSQL的许可错误 - License error using Benchmark.NET + DevArt dotConnect for PostgreSQL 如何在DevArt PostgreSql dotConnect中处理复合类型参数 - How to deal with composite type arguments at DevArt PostgreSql dotConnect DevArt dotConnect for Oracle在EF 4.0字符串上具有奇怪的行为 - DevArt dotConnect for Oracle with strange behavior on strings with EF 4.0 如何使用 Devart dotConnect Express MySQL 获得 MySQL 时间分数? - How to get MySQL time fraction with Devart dotConnect Express MySQL? Devart DotConnect 在针对 Oracle 使用实体框架 6 时得到了意外的长小数点 - Devart DotConnect got unexpected long decimal point for me while using entity framework 6 against Oracle 使用 Entity Framework Code First 连接到带有 devart dotconnect 的旧版 Oracle 数据库 - Using Entity Framework Code First to connect to Legacy Oracle Database with devart dotconnect 在Devart Connectory Mysql中使用事务范围的正确方法 - Right way of using transaction scope with Devart Connectory Mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM