I am getting the following error on production server. It works well on localhost.
Error: Sequence contains more than one element
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
That is an
InvalidOperationExceptionthrown by theSinglemethod.This method is supposed to return only one element, and your query is returning more than one, you have to check the criteria you use on your query.
It will also throw an exception if it doesn’t find an element. You can use
SingleOrDefault()method to return null (or default value, i.e. 0 for int) if there are no records.If you are expecting multiple elements but just one the first one, you can use
Firstinstead ofSingleorFirstOrDefault.