title: Error Getting Record "LINQ to Entities does not recognize the method"
body: <p>In the following code, I am trying to get a profile for the user that is currently logged in.</p>
  
  <pre><code>Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = Membership.GetUser.ProviderUserKey).Single
  </code></pre>
  
  <p>The error is "LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression."</p>
  
  <p>Does anyone know what's wrong with this, or is there a better way... And, how can I make this more secure; i.e. add a condition if no record is found?</p>
  
  <p>I am using VB ASP.NET MVC 3.</p>
  
  <p>Thank you.</p>
  
  <p>Edit: </p>
  
  <p>Here's my new code:</p>
  
  <pre><code>        Dim db1 As UserProfileDbContext = New UserProfileDbContext
          Dim user = Membership.GetUser()
          Dim key As Guid = user.ProviderUserKey
          Dim finalKey = key.ToString
          Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = finalKey).Single
          Dim companyId = userProfile.CompanyId
  </code></pre>