Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
CSS
Hi,

I Get a Error Like this :

An exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code

Additional information: Sequence contains more than one element

i want to get team member details based on teamid
this is my tables :

this is my stored procedure :

GO
ALTER PROCEDURE [dbo].[uspGetAllTeamMembers](@TeamID INT)

AS

BEGIN


SELECT m.MemberID,

m.MemberName,

m.MemberStatus,

ml.MemberLoginName,

tm.MemberJoinedDate,

tm.MemberLeftDate


FROM TeamMember tm

INNER JOIN MemberLogin ml

ON tm.MemberLoginID = ml.MemberLoginID

INNER JOIN Member m

ON m.MemberID = ml.MemberID

WHERE tm.TeamID = @TeamID


END
and this is my backend code :

 public TeamMemberData GetAllTeamMembers(int teamid)
        {
            var getteam = (from t in _DataContext.uspGetAllTeamMembers(teamid) select new TeamMemberData { MemberID=t.MemberID, MemberName=t.MemberName,MemberStatus=t.MemberStatus }).SingleOrDefault();

            return getteam;
        }

I'm using linq to sql stored procedure
please give a help
Posted

1 solution

SingleOrDefault returns an exception if the sequence contains two or more elements - the documentation makes that very clear: https://msdn.microsoft.com/en-us/library/vstudio/bb342451(v=vs.100).aspx[^]

Which means that your TeamMember table contains at least two TeamID values which match the ID you supplied.
Look at your data, or use FirstOrDefault instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900