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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:55:13+00:00 2026-05-26T18:55:13+00:00

I know I’m doing something wrong here, I just don’t know what as I’m

  • 0

I know I’m doing something wrong here, I just don’t know what as I’m not very sure what the issue is. Here’s the code which is called:

The call

System.Linq.Expressions.Expression<Func<AccountDataModel, bool>> deleg = 
                            (m => m.Email == model.Email);
                        AccountDataModel query = database.FindBy(deleg);

Where the call leads to

public T FindBy(Expression<Func<T, bool>> expression)
        {
            return FilterBy(expression).Single();
        }

public IQueryable<T> FilterBy(Expression<Func<T, bool>> expression)
        {
            return All().Where(expression).AsQueryable();
        }

public IQueryable<T> All()
        {
            return (from data in _session.Query<T>()
                   select data);
        }

The exception thrown

Sequence contains no elements

Ze details

Basically, what I’m trying to test right now is a registration module on my website which is supposed to search for an email which has been provided to see if it exists. I have an encrypted email address hidden in the database (and, yes, the email in the model has been encrypted as well) which is supposed to match up with the registration email provided. The problem is that no results are being returned.

What exactly am I doing wrong here?

  • 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-26T18:55:14+00:00Added an answer on May 26, 2026 at 6:55 pm

    Your call to .Single will throw this exception when the sequence is empty. If it is possible that no matches will be found, you should use .SingleOrDefault, which will return null if no matches exist.

    It’s very important to Understand the differences between Single, SingleOrDefault, First, and FirstOrDefault.

    Here’s a helpful visualization of these methods:

    ╔═════════════════╦═════════════╦═════════╦═════════════════════╗
    ║                 ║ [] (Empty)  ║ ["one"] ║ ["one", "two",...]  ║
    ╠═════════════════╬═════════════╬═════════╬═════════════════════╣
    ║ FirstOrDefault  ║ null        ║ "one"   ║ "one"               ║
    ║ First           ║ Exception   ║ "one"   ║ "one"               ║
    ║ SingleOrDefault ║ null        ║ "one"   ║ Exception           ║
    ║ Single          ║ Exception   ║ "one"   ║ Exception           ║
    ╚═════════════════╩═════════════╩═════════╩═════════════════════╝
    ╔═════════════════╦═════════════╦═════════╦═════════════════════╗
    ║ Error messages: ║ no elements ║         ║ multiple elements   ║
    ╚═════════════════╩═════════════╩═════════╩═════════════════════╝
    
    

    As you can see, FirstOrDefault is the only one that won’t throw an exception.

    So, what it comes down to is this:
    The ONLY reason to use First, SingleOrDefault, or Single, is so that an Exception will be thrown if your results are not as you expect!
    This will give you a better debugging experience, and gives your code better semantic meaning.

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

Sidebar

Related Questions

I know that I can do something like $int = (int)99; //(int) has a
I know that design patterns is generally something that's connected to OO programming, but
I know very little about Agile but I wonder if there is any difference
I know regex and substrings is a common question on here but i can
I know LINQ has a SequenceEquals method. This method makes sure each item value
I know its a not a new concept that my site is perfect on
I know it is common that we use the code below to embed a
Know of a way to mock %[]? I'm writing tests for code that makes
I know it's not a good idea to loop SQL queries, so I would
I know we already have many posts about this topic, but I just cannot

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.