Why is this error, 'Sequence contains no elements', happening?

前端 未结 3 1410
离开以前
离开以前 2020-12-30 23:42

I am getting an Invalid Operation Exception, the stack is down below. I think it is because db.Responses.Where(y => y.ResponseId.Equals(item.ResponseId)).First();

3条回答
  •  不知归路
    2020-12-30 23:53

    In the following line.

    temp.Response = db.Responses.Where(y => y.ResponseId.Equals(item.ResponseId)).First();
    

    You are calling First but the collection returned from db.Responses.Where is empty.

提交回复
热议问题