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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:08+00:00 2026-05-24T23:48:08+00:00

For some odd reason, I am unable to access the properties of this object

  • 0

For some odd reason, I am unable to access the properties of this object EVEN if I cast it as its model type. Does anyone have an idea as to why? (It may be obvious, but I’m pretty new to C# so please be patient! :o) )

Users currentUser = new Users();            
currentUser = (from x in db_tc.Users where x.Id == Convert.ToInt32(User.Identity.Name) select x);

When I call currentUser, I am only able to access the CRUD methods and a List<Users> property called usrList. I didn’t create the list definition, so I imagine this is some piece of the Entity framework that is automagically created.

I did try casting currentUser with (Users) prior to the entity query, it didn’t help at all.

  • 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-24T23:48:09+00:00Added an answer on May 24, 2026 at 11:48 pm

    That’s because you’ve only created the query, you haven’t actually executed it. Add Single() (or First() etc.) to get the result:

    var currentUser = (from x in db_tc.Users where x.Id == Convert.ToInt32(User.Identity.Name) select x).SingleOrDefault();
    
    • Single(): Gets the first element of the sequence, but will throw an exception if no element is found or if the sequence has more than one element.
    • First(): Gets the first element of the sequence, but will throw an exception if no element is found.
    • SingleOrDefault() and FirstOrDefault(): Same as above, but will return default(T) instead of throwing on the empty sequence.

    This “deferred execution” aspect of LINQ is probably the most difficult part to understand. The basic idea is that you can build up a query using the query operations (Where(), Select(), etc.), and then you can execute that query to actually get its results, using one of the non-deferred execution operations (Single(), ToList(), etc.)

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

Sidebar

Related Questions

For some odd reason the HTML5 Audio API won't give me access to currentTime
I've been putting up with this for probably too long. For some odd reason,
For some odd reason Internet Explorer won't run my queries properly. I designed this
For some odd reason this line of code is being identified as an This
I'm receiving this error for some odd reason: Fatal error: Class 'crud_model' not found
I have this asp.NET web site that for some odd reason doesn't want to
i'm getting an error 'Object expected' for some odd reason due to jquery, and
I'm ripping my hair out over this one. For some odd reason I cannot
For some odd reason I can no longer access my images in my image
For some odd reason this error occurs when I start up my application. Nov

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.