First post here, so pardon me if its a repeat qossion... :)
Can someone please tell me what is the difference between creating the datacontext as -
- MyDatabaseDataContext db=new MyDatabaseDataContext();
//////
///////// Some code/
2.using (MyDatabaseDataContext db=new MyDatabaseDataContext())
{
///
////// do something.
}
Kirtan PatelPosted Oct 14, 2009, 1:33 AM
Its not Like that
in Both cases you can not create instance with the same name
but what i m telling is
in Second case if object is Disposable then it will dispose it after using (Free Memory) not deleting those object
and if Object is Like SqlConnection it will Close the Connection after Using it in using () { } block
sandeep ramPosted Oct 14, 2009, 2:01 AM
Roei BarPosted Oct 14, 2009, 1:53 AM
1. all objects inside the using block are in the using scope only
2. when the using ends all objects will be disposed from the memory
sandeep ramPosted Oct 14, 2009, 1:23 AM
Thanks for the reply :)
So in the first case, I cannot create another DataContext instance of the same name is it ?
Kirtan PatelPosted Oct 14, 2009, 12:48 AM
in First Code
The Context Data Will be not disposed after using it
while in Second Type of code
the dataContext Will be automatically disposed after using it :)