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

  • Home
  • SEARCH
  • 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 8318237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:53:31+00:00 2026-06-08T21:53:31+00:00

In the following code, I am trying to get a profile for the user

  • 0

In the following code, I am trying to get a profile for the user that is currently logged in.

Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = Membership.GetUser.ProviderUserKey).Single

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.”

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?

I am using VB ASP.NET MVC 3.

Thank you.

Edit:

Here’s my new 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
  • 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-06-08T21:53:34+00:00Added an answer on June 8, 2026 at 9:53 pm

    L2E is trying to render your lamba expression (p) p.UserId = Membership.GetUser.ProviderUserKey in to an SQL Expression which it can use to hit the database.

    However, Membership.GetUser() is a .NET method. L2E is complaining that it doesn’t know how to render this method in to SQL syntax.

    Try this instead:

    Dim user = Membership.GetUser()
    Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = user.ProviderUserKey).Single
    

    edit: MembershipUser.ProviderUserKey is a CLR Object. SQL can’t compare two objects, so you’ll need to strong type it before running the expression. For example, if your user key is a String:

    Dim user = Membership.GetUser()
    Dim key as String= user.ProviderUserKey
    Dim userProfile = db1.UserProfiles.Where(Function(p) p.UserId = key).Single
    

    This should work better because a simple equality expression = is understood by L2E and can be rendered in to an equivilent SQL expression, something like:

    SELECT * FROM Profiles WHERE UserId = @Argument, where the @Argument is supplied by entity framework.

    Also as an aside, L2E will group chained calls until the end, so an expression like:

    db1.UserProfiles.Skip(10).Take(30).Where(Function(p) p.UserId = Membership.GetUser.ProviderUserKey)

    … would still fail, because L2E will combine the Skip Take and Where components in to a single SQL expression. You can force L2E to hit the server by calling ToArray ToList or ToDictionary. That expression could be made valid by changing it to:

    db1.UserProfiles.Skip(10).Take(30).ToArray().Where(Function(p) p.UserId = Membership.GetUser.ProviderUserKey)

    The ToArray forces the execution of the SQL statement, giving you a .NET Array which does support complex lambas.

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

Sidebar

Related Questions

I am trying to get the facebook profile picture of the user logged into
I'm trying to get the following code to work using both Watin and HttpWatch.
I am trying to get the following code to work: if (isset($_POST['file'])){ if(file_exists($_POST['file'])){ echo
I am trying to get a webpage to parse using the following code. <var-def
I'm trying to get the Global Interface Table by using the following code (Delphi):
Using the following code, trying to get the font color to animate on hover,
Im trying to get debugging working without an app.config. I have the following code:
I'm trying to get HTML5's audio tag to work in Chrome. The following code
Trying to get the number of available comports. Used the following code: HKEY hKey;
The following ToolTip code works in WPF . I'm trying to get it to

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.