LinQ to SQL - InsertOnSubmit without SubmitChanges











up vote
0
down vote

favorite












Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :



DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
// db.SubmitChanges();


I didnt call SubmitChanges intentionally .
My question is , can i later find that product and delete it with DeleteOnSubmit method?:



Product product = db.Products.Single(p => p.ID == "1");
db.Products.DeleteOnSubmit(product);


If i cannot , then what the InsertOnSubmit method actually does?



Thank you in advance for your help.










share|improve this question


























    up vote
    0
    down vote

    favorite












    Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :



    DBDataContext db = new DBDataContext();
    Product product = new Product {ID = "1" , Name = "Chair"};
    db.Products.InsertOnSubmit(product);
    // db.SubmitChanges();


    I didnt call SubmitChanges intentionally .
    My question is , can i later find that product and delete it with DeleteOnSubmit method?:



    Product product = db.Products.Single(p => p.ID == "1");
    db.Products.DeleteOnSubmit(product);


    If i cannot , then what the InsertOnSubmit method actually does?



    Thank you in advance for your help.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :



      DBDataContext db = new DBDataContext();
      Product product = new Product {ID = "1" , Name = "Chair"};
      db.Products.InsertOnSubmit(product);
      // db.SubmitChanges();


      I didnt call SubmitChanges intentionally .
      My question is , can i later find that product and delete it with DeleteOnSubmit method?:



      Product product = db.Products.Single(p => p.ID == "1");
      db.Products.DeleteOnSubmit(product);


      If i cannot , then what the InsertOnSubmit method actually does?



      Thank you in advance for your help.










      share|improve this question













      Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :



      DBDataContext db = new DBDataContext();
      Product product = new Product {ID = "1" , Name = "Chair"};
      db.Products.InsertOnSubmit(product);
      // db.SubmitChanges();


      I didnt call SubmitChanges intentionally .
      My question is , can i later find that product and delete it with DeleteOnSubmit method?:



      Product product = db.Products.Single(p => p.ID == "1");
      db.Products.DeleteOnSubmit(product);


      If i cannot , then what the InsertOnSubmit method actually does?



      Thank you in advance for your help.







      linq-to-sql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Văn Hữu

      104




      104
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.




          My question is , can i later find that product and delete it with DeleteOnSubmit method?:




          You won't be able to find the entity because it does not exist in the database.



          Note, if you leave out the find, ie if your code was



          DBDataContext db = new DBDataContext();
          Product product = new Product {ID = "1" , Name = "Chair"};
          db.Products.InsertOnSubmit(product);
          db.Products.DeleteOnSubmit(product);


          Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350239%2flinq-to-sql-insertonsubmit-without-submitchanges%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.




            My question is , can i later find that product and delete it with DeleteOnSubmit method?:




            You won't be able to find the entity because it does not exist in the database.



            Note, if you leave out the find, ie if your code was



            DBDataContext db = new DBDataContext();
            Product product = new Product {ID = "1" , Name = "Chair"};
            db.Products.InsertOnSubmit(product);
            db.Products.DeleteOnSubmit(product);


            Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.






            share|improve this answer

























              up vote
              0
              down vote













              The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.




              My question is , can i later find that product and delete it with DeleteOnSubmit method?:




              You won't be able to find the entity because it does not exist in the database.



              Note, if you leave out the find, ie if your code was



              DBDataContext db = new DBDataContext();
              Product product = new Product {ID = "1" , Name = "Chair"};
              db.Products.InsertOnSubmit(product);
              db.Products.DeleteOnSubmit(product);


              Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.




                My question is , can i later find that product and delete it with DeleteOnSubmit method?:




                You won't be able to find the entity because it does not exist in the database.



                Note, if you leave out the find, ie if your code was



                DBDataContext db = new DBDataContext();
                Product product = new Product {ID = "1" , Name = "Chair"};
                db.Products.InsertOnSubmit(product);
                db.Products.DeleteOnSubmit(product);


                Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.






                share|improve this answer












                The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.




                My question is , can i later find that product and delete it with DeleteOnSubmit method?:




                You won't be able to find the entity because it does not exist in the database.



                Note, if you leave out the find, ie if your code was



                DBDataContext db = new DBDataContext();
                Product product = new Product {ID = "1" , Name = "Chair"};
                db.Products.InsertOnSubmit(product);
                db.Products.DeleteOnSubmit(product);


                Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 17 hours ago









                sgmoore

                11.8k43058




                11.8k43058






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350239%2flinq-to-sql-insertonsubmit-without-submitchanges%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin