Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:24:51+00:00 2026-05-22T16:24:51+00:00

I am using L2S to check if a key already exists, and if it

  • 0

I am using L2S to check if a key already exists, and if it doesnt, create and insert one. This same DataContext is also used to execute other queries within the same C# method. I am implimenting the using keyword to dispose the DataContext after I am done with it. I hooked up sql profiler and saw that it would Login, execute the query, then logout. It seems to do this even if the same DataContext will perform a query or update later. I thought the datacontext only logged in once, and performed all the queries during that one session? Does how often you call SubmitChanges() matter? Or what am i missing?

mock of what i am seeing:

using(Datacontext)
{
      //Audit Login
      var b = DataContext.Table.FirstOrDefault(t=>t.Id == 4);
      //RPC: Completed
      //Audit Logout

       //Audit Login
       var x = DataContext.OtherTable.Any(t=>t.Id == 4);
       //RPC: Completed
      //Audit Logout

}

Update

sql profiler is showing the ‘duration’ of these logouts as a couple hundred milliseconds. Thats time my app is waiting right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:24:51+00:00Added an answer on May 22, 2026 at 4:24 pm

    FirstOrDefault executes a query since it needs to give you a result back, not a potential collection – same goes for Any. When you create a DataContext it doesn’t log in right away. I can assure you, though this may look “bad”, it’s completely fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a L2S query that looks like this: using (MyDC TheDC = new
I've formerly used L2S and am looking at using NHib along with the Sharp
I'm following the fairly standard L2S repository pattern, using the following as one of
I am displaying a list of customer records from SQL Server using L2S where
I am using L2S and an inheritance model for mapping Persons against certain roles.
I am using L2S to access my MSSQL 2008 Express server. I would like
Very strange situation here: I'm using L2S to populate a DataGridView. Code follows: private
Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ
I use L2S at my module. The problem occurs while I'm using the default
I have a query that looks like this: using (MyDC TheDC = new MyDC())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.