I am working on implementing the dotConnect for MySQL. It seems as if it will save an impressive amount of time, and make coding much cleaner and legible. I am curious as to the best method for putting LINQ queries into functions. In LINQ, you have to have a DataContext that you query against. Should I create a new instance of my DataContext each time a function is called, or should I pass a previously created instance of it to the function to query against it.
For example, is it the best to do this?
Code: Select all
public static ProgramContext.Member rMember (int id) {
ProgramDataContext db = new ProgramDataContext();
return (from p in db.Members
where p.Id == id
select p).First();
}
Code: Select all
public static ProgramContext.Member rMember (int id, ProgramDataContext db) {
return (from p in db.Members
where p.Id == id
select p).First();
}
Thank you!
JMax