I am new to Linq to sql. And my question is simple.
Is it a good idea to have DataContext as public static member in DAL to act as singleton?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I generally try to group functionality together for a Data Access class and make that class IDisposable.
Then you Create your DataContext in your constructor and in your dispose method you run your .dispose() call on the DataContext.
So then when you need something from that class you can wrap it in a using statement, and make a bunch of calls all using the same DataContext.
It’s pretty much the same effect as using a Static DataContext, but means you don’t forget to close down the connection, and it seems a bit more OO than making things static.
Then in your class