Sequence contains no matching element

前端 未结 5 2127
滥情空心
滥情空心 2020-11-30 00:48

I have an asp.net application in which I am using linq for data manipulation. While running, I get the exception \"Sequence contains no matching element\".

i         


        
5条回答
  •  失恋的感觉
    2020-11-30 01:18

    Use FirstOrDefault. First will never return null - if it can't find a matching element it throws the exception you're seeing.

    _dsACL.Documents.FirstOrDefault(o => o.ID == id);
    

提交回复
热议问题