System.InvalidOperationException: Sequence contains more than one element
問題發生點:
System.InvalidOperationException: Sequence contains more than one element
Generated: Mon, 13 Mar 2023 04:28:17 GMT
System.InvalidOperationException: Sequence contains more than one element
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
在資料庫SELECT的使用PK為欄位的Where條件,居然會出現撈出多筆的情況,導致PetaPOCO因 為SingleOrDefault 接收資料庫資料造成以上錯誤發生,初步認為是JOIN資料時,可能因同步或是有資料表在INSERT或是UPDATE,導致出現兩筆
解決方式:
1.針對每個JOIN的Table做 WITH(NOLOCK),原本只有在 FROM Table WITH(NOLOCK) 只寫了第一個
2.增加Where條件