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 908889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:47:21+00:00 2026-05-15T16:47:21+00:00

I have (well had) a bit of code that would get me my lovely

  • 0

I have (well had) a bit of code that would get me my lovely username and populate a session with its contents:

ManagePreferencesDataContext lg = new ManagePreferencesDataContext();
            IEnumerable<tblManagePreference> ol;

            ol = from login in lg.tblManagePreferences
                 where login.Username == Membership.GetUser().ToString()
                 select login;

            if (ol.Count() > 0)
            {
                Session["Sess_MemberID"] = ol.First().MemberID;
                Session["Sess_LocationID"] = ol.First().LocationID;

                lblMemberID.Text = Session["Sess_MemberID"].ToString();
                lblLocationID.Text = Session["Sess_LocationID"].ToString();
            }

            else
            {

Fantastic! That worked fine and dandy. However, I’ve been instructed to move over to sunny Entity Framework and I’ll be honest, we don’t get on i.e. I don’t know enough about it – I know very little to start with!

Anyway, I have attempted to amend the above code with the following:

VDSORDAL.PDC_VDSOREntities lg = new VDSORDAL.PDC_VDSOREntities();
            IEnumerable<VDSORDAL.tblUserPreference> ol;

            ol = from login in lg.tblUserPreferences
                 where login.Username == Membership.GetUser().UserName
                 select login;

            if (ol.Count() > 0)
            {
                Session["VDS_MemberID"] = ol.First().MemberID;
                Session["VDS_LocationID"] = ol.First().LocationID;
                Session["VDS_Username"] = ol.First().Username;

                lblMemberID.Text = Session["VDS_MemberID"].ToString();
                lblLocationID.Text = Session["VDS_LocationID"].ToString();
            }
            else
            {
            }
          }

However, when I try to run this I receive the error that forms the title of this here question.

So in summary – where am I going wrong.

As alway, many apologies for what is most likely a very simple question.

  • 1 1 Answer
  • 3 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-15T16:47:22+00:00Added an answer on May 15, 2026 at 4:47 pm

    You’re 99% there. The problem is that you’re passing a method (GetUsername) into the L2E parser that it doesn’t understand. You want to deal with values rather than method calls in this case:

    VDSORDAL.PDC_VDSOREntities lg = new VDSORDAL.PDC_VDSOREntities();
                IEnumerable<VDSORDAL.tblUserPreference> ol;
                string userName = Membership.GetUser().UserName; //store the value
                ol = from login in lg.tblUserPreferences
                     where login.Username == userName 
                     select login;
    
                if (ol.Count() > 0)
                {
                    Session["VDS_MemberID"] = ol.First().MemberID;
                    Session["VDS_LocationID"] = ol.First().LocationID;
                    Session["VDS_Username"] = ol.First().Username;
    
                    lblMemberID.Text = Session["VDS_MemberID"].ToString();
                    lblLocationID.Text = Session["VDS_LocationID"].ToString();
                }
                else
                {
                }
              }
    

    This happens because the LINQ to Entities Provider evaluates the expression to build the query. It can’t execute the method on the Membership object.

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

Sidebar

Related Questions

I recently came across a bit of not-well-tested legacy code for writing data that's
I have a well div, and I would like to attach a small text/image
I have a well-developed application for a phone, but I would like to add
Well i have a div tag that i show as a modal dialog this
well I have that problem, im using a lightbox srcipt and im opening an
I have run into a bit of a problem, well not sure if it
I have been trying to write a constructor function that would make an object
I have a well formed XHTML page. I want to find the destination URL
I have a well defined service contract which exposes a bunch of methods. We
Starting a new rails project and we have a well-thought-out color palette, and want

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.