Jump to content

Recommended Posts

Posted

Question to all of you folks out there that are already proficient with LINQ.* I'm updating one of my older 2.0 apps to be 3.5 and ripping out most of my database code and replacing with LINQ.* The long and short of the situation is that for any specific form, there is a separate DataContext associated with it that performs the various updates, queries, etc. as needed.

 

What I'm wondering is the best way to manage the lifetime of the DataContext.* I don't want to just instantiate it and leave it there for each form, as it could potentially be alive for several hours.* Does it make sense to do something like the following for various operations:

 

_mdc = new MyDataContext();

// Operations here

_mdc.Dispose();

 

Or is it more appropriate to specifically just close the connection, like:

 

_mdc.Connection.Open();

// Operations here

_mdc.Connection.Close();

 

Are there*recommended 'best practices'*for this sort of thing?

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...