The problem is that you are using SingleOrDefault
. This method will only succeed when the collections contains exactly 0 or 1 element. I believe you are looking for FirstOrDefault
which will succeed no matter how many elements are in the collection.
Related Posts:
- System.web.mvc missing
- Extension methods must be defined in a non-generic static class
- WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery
- Extension methods must be defined in a non-generic static class
- How to use the “Using” statement in ASP.net razor webpages?
- How do I concatenate two arrays in C#?
- c# .net change label text
- LINQ query on a DataTable
- Linq: GroupBy, Sum and Count
- How to set session timeout in web.config
- .Net 4.8 Support for Windows 10 ends in 26 days?
- What is a NullReferenceException, and how do I fix it?
- How do I get a random YouTube video with the YouTube API?
- An existing connection was forcibly closed by the remote host
- How can I convert String to Int?
- What is a NullReferenceException, and how do I fix it?
- I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome
- Could not load file or assembly or one of its dependencies
- Error : Could not load file or assembly or one of it’s dependencies
- Group by in LINQ
- LINQ’s Distinct() on a particular property
- Priority queue in .Net
- What is the difference between int, Int16, Int32 and Int64?
- The request was aborted: Could not create SSL/TLS secure channel
- Twilio TwilioRestClient does not contain a definition for SendSmsMessage
- How to open .dll files to see what is written inside?
- how does Request.QueryString work?
- Windows .NET API / Windows 7 / Bluetooth communication with Intel Curie Arduino / Genuino 101
- Nullable object must have a value?
- Sequence contains no elements?
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- How to resolve this System.IO.FileNotFoundException
- What is WebResource.axd?
- What does vary:accept-encoding mean?
- What is clr.dll on .Net framework and what does it do?
- what is this oleaut32.dll?
- How can I secure passwords stored inside web.config?
- Associating enums with strings in C#
- Proper Linq where clauses
- How to resolve this System.IO.FileNotFoundException
- C# Gridview CheckBox Field VS (Template Field + CheckBox)
- How can I get the application’s path in a .NET console application?
- How do I create a Shared Code project (.shproj)
- There is no argument given that corresponds to the required formal parameter – .NET Error
- How do I remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- calling javascript function on OnClientClick event of a Submit button
- Could not establish trust relationship for SSL/TLS secure channel — SOAP
- Name does not exist in the current context
- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
- IEnumerable vs List – What to Use? How do they work?
- Member ‘
‘ cannot be accessed with an instance reference - Sequence contains no matching element
- The remote server returned an error: (407) Proxy Authentication Required
- when do you need .ascx files and how would you use them?
- Merge two (or more) lists into one, in C# .NET
- How to open a new form from another form
- HTML.ActionLink method
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- System.ComponentModel.Win32Exception: Access is denied Error
- .NET graph library around?
- An object reference is required to access a non-static member
- Task vs Thread differences
- Merging two arrays in .NET
- String was not recognized as a valid DateTime ” format dd/MM/yyyy”
- XmlSerializer – There was an error reflecting type
- Substring index and length must refer to a location within the string
- Run Command Prompt Commands
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- Visual Studio keeps crashing
- How can I implement static methods on an interface?
- How to add List<> to a List<> in asp.net [duplicate]
- Catch multiple exceptions at once?
- How to delete a file after checking whether it exists
- c# Show Windows Form
- How do I exit a WPF application programmatically?
- How to get the URL of the current page in C#
- Linq select objects in list where exists IN (A,B,C)
- What is a quick way to force CRLF in C# / .NET?
- How to enable assembly bind failure logging (Fusion) in .NET
- How to make inline functions in C#
- How to properly make a http web GET request
- Strip double quotes from a string in .NET
- How to create a new object instance from a Type
- Cannot drop database because it is currently in use
- does not implement interface member
- Using FolderBrowserDialog in WPF application
- How to make Check Box List in ASP.Net MVC
- Is there an equivalent to the C# “var” keyword in C++/CLI?
- When should I use a List vs a LinkedList
- Parser Error Message: Could not load type ‘sometype’
- Playing a MP3 file in a WinForm application
- The server tag is not well formed error
- Iif equivalent in C#
- Quickest way to compare two generic lists for differences
- Best way to randomize an array with .NET
- Encrypt and decrypt a string in C#?
- Using .Select and .Where in a single LINQ statement
- Unrecognized escape sequence for path string containing backslashes