N
Neil Chambers
All,
I have a class describing various actions to take against a LINQ to SQL
datasource. What are the pros/cons of instantiating the LINQ object either
in the root of the class (for lack of a better description) or within each
of the methods? I am naturally drawn to instantiating the LINQ object in the
root but some examples I've seen preffer to keep this local to the methods.
Is there a compelling reason for this? It seems that garbage collection
would work the same for either approach but with less overhead instantiating
in the 'root' (at least to my relatively novice eye).
//instantiate in 'root' of class - this approach feels less wasteful
public class myDB
{
private myLINQObject db = new myLINQObject();
public void action1(){for i in db.tbl1...}
public void action2(){for i in db.tbl2...}
}
//instantiate in methods - seems like a lot of repetition when I know the
object will be needed anyway
public class myDB
{
public void action1()
{myLINQObject db = new myLINQObject();
for i in db.tbl1...}
public void action2(){
myLINQObject db = new myLINQObject();
for i in db.tbl2...}
}
Many thanks
n
I have a class describing various actions to take against a LINQ to SQL
datasource. What are the pros/cons of instantiating the LINQ object either
in the root of the class (for lack of a better description) or within each
of the methods? I am naturally drawn to instantiating the LINQ object in the
root but some examples I've seen preffer to keep this local to the methods.
Is there a compelling reason for this? It seems that garbage collection
would work the same for either approach but with less overhead instantiating
in the 'root' (at least to my relatively novice eye).
//instantiate in 'root' of class - this approach feels less wasteful
public class myDB
{
private myLINQObject db = new myLINQObject();
public void action1(){for i in db.tbl1...}
public void action2(){for i in db.tbl2...}
}
//instantiate in methods - seems like a lot of repetition when I know the
object will be needed anyway
public class myDB
{
public void action1()
{myLINQObject db = new myLINQObject();
for i in db.tbl1...}
public void action2(){
myLINQObject db = new myLINQObject();
for i in db.tbl2...}
}
Many thanks
n