Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's my code
[CommandMethod(nameof(NestedTransactionsMissingEntity))]
public static void NestedTransactionsMissingEntity()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trOuter = db.TransactionManager.StartTransaction())
{
// Create a line
Line l1 = new Line(new Point3d(0, 0, 0), new Point3d(10, 0, 0));
var btr = (BlockTableRecord)trOuter.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(l1);
trOuter.AddNewlyCreatedDBObject(l1, true);
using (Transaction trInner1 = db.TransactionManager.StartTransaction())
{
var extendsInner1 = trOuter.GetAllObjects();
var l2 = new Line(new Point3d(0 + 100, 0, 0), new Point3d(10 + 100, 0, 0));
btr.AppendEntity(l2);
trInner1.AddNewlyCreatedDBObject(l2, true);
trInner1.Commit(); //after commit then l2 should be in trOuter right?
}
using (Transaction trInner2 = db.TransactionManager.StartTransaction())
{
var extentsInner2 = trOuter.GetAllObjects(); //l2 not in trOuter? ditto for trInner2
var l3 = new Line(new Point3d(0 + 1000, 0, 0), new Point3d(10 + 1000, 0, 0));
btr.AppendEntity(l3);
trInner2.AddNewlyCreatedDBObject(l3, true);
trInner2.Commit(); //after commit then l3 should be in trOuter right?
}
var extentsOuter = trOuter.GetAllObjects(); // l2 and l3 not in trOuter?
trOuter.Commit();
}
ed.Regen();
}
You can see that the inner transaction committed entities ( l2 and l3) is not available after the fact in outer transaction. Why?
And how to ensure that they are available in outer transaction?
##########
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Solved! Go to Solution.