SingleOrDefault() throws an exception on more than one element

后端 未结 7 2017
野性不改
野性不改 2021-02-05 12:17

I\'m getting an exception whenever I fetch like this

Feature f = o.Features.SingleOrDefault(e => e.LinkName == PageLink);

because this can r

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 12:38

    If you are using SingleOrDefault if the condition satisfy more than result it will throw error.

    you can achieve your result by using FirstOrDefault

提交回复
热议问题