dispose on entity framework
-
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?
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 -
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?
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
-
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?
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 ofDispose
. 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
-
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 KreskowiakMy 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
-
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
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 af.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 -
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 af.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 Kreskowiakok 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 !
-
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 !
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 -
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 -
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
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 -
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 -
Neither. You've never shown a dialog form before, have you?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak