<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inner Transaction committed entity not available? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231560#M1345</link>
    <description>&lt;P&gt;Transaction.GetAllObjects gets the objects opened or added to this transaction.&lt;/P&gt;
&lt;P&gt;TransactionManager.GetAllObjects gets all objects from all transactions active.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod(nameof(NestedTransactions))]
public static void NestedTransactions()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;
    var tm = db.TransactionManager;

    void TransactionObjects(string name, Transaction tr) =&amp;gt;
        ed.WriteMessage($"\n{name}: {string.Join(", ", tr.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

    void TransactionManagerObjects() =&amp;gt;
        ed.WriteMessage($"\nTM: {string.Join(", ", tm.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

    using (Transaction t1 = tm.StartTransaction())
    {
        var currentSpace = (BlockTableRecord)t1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        var line = new Line(new Point3d(-10.0, -10.0, 0.0), new Point3d(10.0, 10.0, 0.0));
        currentSpace.AppendEntity(line);
        t1.AddNewlyCreatedDBObject(line, true);

        TransactionObjects("T1", t1);
        TransactionManagerObjects();

        using (var t2 = tm.StartTransaction())
        {
            var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10.0);
            currentSpace.AppendEntity(circle);
            t2.AddNewlyCreatedDBObject(circle, true);

            TransactionObjects("T2",t2);
            TransactionObjects("T1", t1);
            TransactionManagerObjects();

            using (var t3 = tm.StartTransaction())
            {
                var arc = new Arc(Point3d.Origin, 12.0, 0.0, Math.PI);
                currentSpace.AppendEntity(arc);
                t3.AddNewlyCreatedDBObject(arc, true);

                TransactionObjects("T3", t3);
                TransactionObjects("T2", t2);
                TransactionObjects("T1", t1);
                TransactionManagerObjects();

                t3.Commit();
            }
            TransactionObjects("T2", t2);
            TransactionManagerObjects();

            t2.Commit();
        }
        TransactionObjects("T1", t1);
        TransactionManagerObjects();

        t1.Commit();
    }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 27 Dec 2024 09:56:01 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2024-12-27T09:56:01Z</dc:date>
    <item>
      <title>Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231433#M1339</link>
      <description>&lt;P&gt;Here's my code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;   [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();
   }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can see that the inner transaction committed entities ( l2 and l3) is not available after the fact in outer transaction. Why?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And how to ensure that they are available in outer transaction?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:07:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231433#M1339</guid>
      <dc:creator>soonhui</dc:creator>
      <dc:date>2024-12-27T08:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231451#M1340</link>
      <description>&lt;P&gt;You must declare them in trOuter. Line l2 = null;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:22:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231451#M1340</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2024-12-27T08:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231457#M1341</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7472042"&gt;@soonhui&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;how to ensure that they are available in outer transaction?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As said in another topic, you should never use a DBObject outside of the the scope of the transaction this object has been added to because it has been disposed with this transcation.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:38:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231457#M1341</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-12-27T08:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231463#M1342</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;, I'm not entirely sure what's your point relevance to my central question, namely&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; var extentsOuter = trOuter.GetAllObjects();  // l2 and l3 not in trOuter? &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would have expected that by that time the l2 and l3 are already in the object list in the trOuter ( because the inner transaction has been committed).&amp;nbsp; This is the impression I got when I read &lt;A href="https://adndevblog.typepad.com/autocad/2012/08/whats-the-meaning-of-getallobjects-in-the-context-of-nested-transactions.html" target="_blank" rel="noopener"&gt;this&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;T1
    ...
    T1-&amp;gt;getAllObjects();            //only T1 objects
    T2
        ...   
        T2-&amp;gt;getAllObjects();        //only T2 objects
        T1-&amp;gt;getAllObjects();        //only T1 objects
        T3
            ...
            T3-&amp;gt;getAllObjects();    //only T3 objects
            T2-&amp;gt;getAllObjects();    //only T2 objects
            T1-&amp;gt;getAllObjects();    //only T1 objects
        end T3
        T2-&amp;gt;getAllObjects();        //both T2 and T3 objects
    end T2
    T1-&amp;gt;getAllObjects();            //T1, T2 and T3 objects  
end T1&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:44:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231463#M1342</guid>
      <dc:creator>soonhui</dc:creator>
      <dc:date>2024-12-27T08:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231469#M1343</link>
      <description>&lt;P&gt;Please, stop reply in one topic to the answers given in another topic, it makes boths topics unreadable separately.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:50:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231469#M1343</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-12-27T08:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231478#M1344</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;, I'm confining my reply to this topic only-- no cross pollination. This topic has &lt;EM&gt;nothing&lt;/EM&gt; to do with variable moving outer scope ( not from me anyway), just why GetAllObjects are not really getting the objects that have been committed in the previous inner transaction.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 08:57:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231478#M1344</guid>
      <dc:creator>soonhui</dc:creator>
      <dc:date>2024-12-27T08:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231560#M1345</link>
      <description>&lt;P&gt;Transaction.GetAllObjects gets the objects opened or added to this transaction.&lt;/P&gt;
&lt;P&gt;TransactionManager.GetAllObjects gets all objects from all transactions active.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod(nameof(NestedTransactions))]
public static void NestedTransactions()
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var db = doc.Database;
    var ed = doc.Editor;
    var tm = db.TransactionManager;

    void TransactionObjects(string name, Transaction tr) =&amp;gt;
        ed.WriteMessage($"\n{name}: {string.Join(", ", tr.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

    void TransactionManagerObjects() =&amp;gt;
        ed.WriteMessage($"\nTM: {string.Join(", ", tm.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

    using (Transaction t1 = tm.StartTransaction())
    {
        var currentSpace = (BlockTableRecord)t1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        var line = new Line(new Point3d(-10.0, -10.0, 0.0), new Point3d(10.0, 10.0, 0.0));
        currentSpace.AppendEntity(line);
        t1.AddNewlyCreatedDBObject(line, true);

        TransactionObjects("T1", t1);
        TransactionManagerObjects();

        using (var t2 = tm.StartTransaction())
        {
            var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10.0);
            currentSpace.AppendEntity(circle);
            t2.AddNewlyCreatedDBObject(circle, true);

            TransactionObjects("T2",t2);
            TransactionObjects("T1", t1);
            TransactionManagerObjects();

            using (var t3 = tm.StartTransaction())
            {
                var arc = new Arc(Point3d.Origin, 12.0, 0.0, Math.PI);
                currentSpace.AppendEntity(arc);
                t3.AddNewlyCreatedDBObject(arc, true);

                TransactionObjects("T3", t3);
                TransactionObjects("T2", t2);
                TransactionObjects("T1", t1);
                TransactionManagerObjects();

                t3.Commit();
            }
            TransactionObjects("T2", t2);
            TransactionManagerObjects();

            t2.Commit();
        }
        TransactionObjects("T1", t1);
        TransactionManagerObjects();

        t1.Commit();
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 27 Dec 2024 09:56:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13231560#M1345</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-12-27T09:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Inner Transaction committed entity not available?</title>
      <link>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13238563#M1346</link>
      <description>&lt;P&gt;In addition to&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; comment, here's a code snippet and comments that illustrates the relationship between nested transaction and the Abort() function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        [CommandMethod(nameof(NestedTransactions))]
        public static void NestedTransactions()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var tm = db.TransactionManager;

            void TransactionObjects(string name, Transaction tr) =&amp;gt;
                ed.WriteMessage($"\n{name}: {string.Join(", ", tr.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

            void TransactionManagerObjects() =&amp;gt;
                ed.WriteMessage($"\nTM: {string.Join(", ", tm.GetAllObjects().Cast&amp;lt;DBObject&amp;gt;().Select(e =&amp;gt; e.GetType().Name))}");

            using var t1 = tm.StartTransaction();
            var currentSpace = (BlockTableRecord)t1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
            var line = new Line(new Point3d(-10.0, -10.0, 0.0), new Point3d(10.0, 10.0, 0.0));
            currentSpace.AppendEntity(line);
            t1.AddNewlyCreatedDBObject(line, true);

            TransactionObjects("T1", t1);
            TransactionManagerObjects();

            using (var t2 = tm.StartTransaction())
            {
                var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10.0);
                currentSpace.AppendEntity(circle);
                t2.AddNewlyCreatedDBObject(circle, true);

                TransactionObjects("T2", t2);
                TransactionObjects("T1", t1);
                TransactionManagerObjects();

                using (var t3 = tm.StartTransaction())
                {
                    var arc = new Arc(Point3d.Origin, 12.0, 0.0, Math.PI);
                    currentSpace.AppendEntity(arc);
                    t3.AddNewlyCreatedDBObject(arc, true);

                    TransactionObjects("T3", t3);
                    TransactionObjects("T2", t2);  //still only 1 object for t2, 
                    TransactionObjects("T1", t1);
                    TransactionManagerObjects();

                    t3.Commit();
                }
                TransactionObjects("T2", t2);//still only 1 object for t2. the objects added in the nested transaction t3 ( with or without commit) is not related to t2 per se. 
                TransactionManagerObjects();  //tm has 4 objects, 2 from t1, t3 and t2 contribute one each

                t2.Abort(); //tm has only 2 objects from t1. t3 and t2 no more contributes. 
            }
            TransactionObjects("T1", t1);
            TransactionManagerObjects();

            t1.Commit();
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 02 Jan 2025 10:25:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inner-transaction-committed-entity-not-available/m-p/13238563#M1346</guid>
      <dc:creator>soonhui</dc:creator>
      <dc:date>2025-01-02T10:25:34Z</dc:date>
    </item>
  </channel>
</rss>

