Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. dispose on entity framework

dispose on entity framework

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcode25
    wrote on last edited by
    #1

    Hello ! have a form on vb.net bounded with a bindingsource on entity framework. when the form is closed , should i dispose entity or bindingsource?

    D L D 3 Replies Last reply
    0
    • D dcode25

      Hello ! have a form on vb.net bounded with a bindingsource on entity framework. when the form is closed , should i dispose entity or bindingsource?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Rule of thumb: If the object has a Dispose method, call it before the object goes out of scope.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      D 1 Reply Last reply
      0
      • D dcode25

        Hello ! have a form on vb.net bounded with a bindingsource on entity framework. when the form is closed , should i dispose entity or bindingsource?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        As Dave said. unless you didn't create, or cause the creation, of the object (as in Brushes.Black). :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        1 Reply Last reply
        0
        • D dcode25

          Hello ! have a form on vb.net bounded with a bindingsource on entity framework. when the form is closed , should i dispose entity or bindingsource?

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          There is a blog discussing Dispose on MSDN; when-to-call-dispose[^] There is also a link within the blog on in depth guidelines on use and implementation of Dispose. As you will see at the bottom of the Blog there is a summary guidance section details the MUST category and the Maybe's.......

          Dave Find Me On: Web|Facebook|Twitter|LinkedIn


          Folding Stats: Team CodeProject

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            Rule of thumb: If the object has a Dispose method, call it before the object goes out of scope.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            D Offline
            D Offline
            dcode25
            wrote on last edited by
            #5

            My request is for a specific situation : Entity framework created directly from existing database (sql server), A form with a bindingsource. When the form is open the code is : Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim f As unEntities f = New unEntities FaBindingSource.DataSource = f.fas End Sub What can i put on : Private Sub Form1_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed f.dispose ???????????????? FaBindingsource.dispose ?????? FaBindingsource.clear() ?????????? or ???????? End Sub Thank you

            D 1 Reply Last reply
            0
            • D dcode25

              My request is for a specific situation : Entity framework created directly from existing database (sql server), A form with a bindingsource. When the form is open the code is : Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim f As unEntities f = New unEntities FaBindingSource.DataSource = f.fas End Sub What can i put on : Private Sub Form1_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed f.dispose ???????????????? FaBindingsource.dispose ?????? FaBindingsource.clear() ?????????? or ???????? End Sub Thank you

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I highly suggest you pick up and work through a book on C#. Since f is declared in the Load event handler method, it cannot be seen outside of that method. Trying to do a f.Dipose() anywhere else will cause the compiler to throw an error at you. Next, no, you don't have to Dispose a BindingSource, even though it has a Dispose method.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              D 1 Reply Last reply
              0
              • D Dave Kreskowiak

                I highly suggest you pick up and work through a book on C#. Since f is declared in the Load event handler method, it cannot be seen outside of that method. Trying to do a f.Dipose() anywhere else will cause the compiler to throw an error at you. Next, no, you don't have to Dispose a BindingSource, even though it has a Dispose method.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                D Offline
                D Offline
                dcode25
                wrote on last edited by
                #7

                ok maybe my question is wrong . The real situation is : i have a form with select buttons that i use to move through records.I select for example the third record and after that i close the form.If a reopen the form , the third record is selected.i don't want this situation.When the form is loaded , the first record should be selected.I know that i can put something like moveToFirst method , but i dont want this.I try to put bindingsource.dispose on closing form sub , and this has not resolved the problem.if i put bindingsource.clear() the problem is resolved. So i just want to understand the situation , after the form is closed the bindingsource keeps the records ?? Anyway , thank you !

                D 1 Reply Last reply
                0
                • D dcode25

                  ok maybe my question is wrong . The real situation is : i have a form with select buttons that i use to move through records.I select for example the third record and after that i close the form.If a reopen the form , the third record is selected.i don't want this situation.When the form is loaded , the first record should be selected.I know that i can put something like moveToFirst method , but i dont want this.I try to put bindingsource.dispose on closing form sub , and this has not resolved the problem.if i put bindingsource.clear() the problem is resolved. So i just want to understand the situation , after the form is closed the bindingsource keeps the records ?? Anyway , thank you !

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Disposing the thing doesn't have anything to do with this. It sounds as though your problem is that once you dismiss the form, you're reusing it instead of destroying it and creating a new instance of the form. But, you haven't said much about your application of what this form is for so it's pretty difficult to tell you where you're going wrong.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  D 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Disposing the thing doesn't have anything to do with this. It sounds as though your problem is that once you dismiss the form, you're reusing it instead of destroying it and creating a new instance of the form. But, you haven't said much about your application of what this form is for so it's pretty difficult to tell you where you're going wrong.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    D Offline
                    D Offline
                    dcode25
                    wrote on last edited by
                    #9

                    i have a menu on my application.And the code in menu item to open this form is : form1.showdialog After the form is closed using x button

                    D 1 Reply Last reply
                    0
                    • D dcode25

                      i have a menu on my application.And the code in menu item to open this form is : form1.showdialog After the form is closed using x button

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      OK, so after the .ShowDialog call, do what you need to do with the data on the form and .Dispose it. Then in the menu click code you can create a new instance of the form like it never existed before in the first place.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak

                      D 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        OK, so after the .ShowDialog call, do what you need to do with the data on the form and .Dispose it. Then in the menu click code you can create a new instance of the form like it never existed before in the first place.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak

                        D Offline
                        D Offline
                        dcode25
                        wrote on last edited by
                        #11

                        ok. but should i call form1.dispose(true) or form1.dispose(false) ?

                        D 1 Reply Last reply
                        0
                        • D dcode25

                          ok. but should i call form1.dispose(true) or form1.dispose(false) ?

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          Neither. You've never shown a dialog form before, have you?

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups