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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:24:37+00:00 2026-05-10T19:24:37+00:00

I just asked this question . Which lead me to a new question :)

  • 0

I just asked this question. Which lead me to a new question 🙂

Up until this point, I have used the following pattern of selecting stuff with Linq to SQL, with the purpose of being able to handle 0 ‘rows’ returned by the query:

var person = (from p in [DataContextObject].Persons               where p.PersonsID == 1               select new p).FirstOrDefault();  if (person == null) {     // handle 0 'rows' returned. } 

But I can’t use FirstOrDefault() when I do:

var person = from p in [DataContextObject].Persons              where p.PersonsID == 1              select new { p.PersonsID, p.PersonsAdress, p.PersonsZipcode };  // Under the hood, this pattern generates a query which selects specific // columns which will be faster than selecting all columns as the above // snippet of code does. This results in a performance-boost on large tables. 

How do I check for 0 ‘rows’ returned by the query, using the second pattern?

UPDATE:

I think my build fails because I am trying to assign the result of the query to a variable (this._user) declared with the type of [DataContext].User.

this._user = (from u in [DataContextObject].Users               where u.UsersID == [Int32]               select new { u.UsersID }).FirstOrDefault(); 

Compilation error: Cannot implicitly convert type ‘AnonymousType#1’ to ‘[DataContext].User’.

Any thoughts on how I can get around this? Would I have to make my own object?

  • 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. 2026-05-10T19:24:38+00:00Added an answer on May 10, 2026 at 7:24 pm

    Regarding your UPDATE: you have to either create your own type, change this._user to be int, or select the whole object, not only specific columns.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might want to extend your current approach a bit,… May 12, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer You need to analyze this problem in terms of what's… May 12, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer From what I understand a closure also has to have… May 12, 2026 at 12:40 am

Related Questions

This is a little subjective I think; I'm not sure if the opinion will
I always felt that expecting exceptions to be thrown on a regular basis and
I am really new to Haskell (Actually I saw Real World Haskell from O'Reilly
I just want to clarify one thing. This is not a question on which

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.