<p>In LINQ to SQL, is it possible to check to see if an entity is already part of the data context before trying to attach it?</p>

<p>A little context if it helps...</p>

<p>I have this code in my <code>global.asax</code> as a helper method.  Normally, between requests, this isn't a problem.  But right after signing in, this is getting called more than once, and the second time I end up trying to attach the <code>Member</code> object in the same unit of work where it was created.</p>

<pre><code>private void CheckCurrentUser()
{
    if (!HttpContext.Current.User.Identity.IsAuthenticated)
    {
        AppHelper.CurrentMember = null;
        return;
    }

    IUserService userService = new UserService();

    if (AppHelper.CurrentMember != null)
        userService.AttachExisting(AppHelper.CurrentMember);
    else
        AppHelper.CurrentMember = userService.GetMember(
            HttpContext.Current.User.Identity.Name,
            AppHelper.CurrentLocation);
}
</code></pre>

My rules:
Don't initialize with the default values in declaration (
```
null
```
,
```
false
```
,
```
0
```
,
```
0.0
```
…).
Prefer initialization in declaration if you don't have a constructor parameter that changes the value of the field.
If the value of the field changes because of a constructor parameter put the initialization in the constructors.
Be consistent in your practice (the most important rule).