我有以下代碼:問題與對象Where子句
IList<CmsUserPermissionGroup> matchingRoles = PermissionGroups.Where(r => r.JournalCode.ToLower() == journalCode.ToLower())
.Where(r => r.CmsRole.ToLower() == role.ToLower())
.Where(r => r.AccessLevel > 0)
,我認爲,如果不返回任何結果將返回一個空列表。實際返回的是以下錯誤:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
我誤解了什麼嗎?還有什麼其他的選擇?
您確定NullReferenceException沒有被生成,因爲您正在調用ToLower()實例的某個屬性爲null? –
似乎是這種情況,正如在下面的答案中已經強調的那樣 - 感謝您的意見。 – MichaelS