У меня есть следующее утверждение:
select new Action {
ParentContentType = action.ParentContentType != null ? (ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType) : null
};
ParentContentType - это обнуляемое перечисление типа ContentType
action.ParentContentType отображается в таблицу базы данных, которая может иметь значение null.
Если action.ParentContentType isnt null, значение enum определяется с помощью:
(ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType)
В случае, когда action.ParentContentType IS null Я пытаюсь установить для nullable перечисления значение null.
Это не компилируется, и я получаю:
Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between ContentType' and '<null>'
EDIT
Я мог создать нулевое значение перечисления .. т.е. ContentType.EMPTY.
Однако:
ParentContentType = action.ParentContentType == null? ContentType.EMPTY: (ContentType) Enum.ToObject (typeof (ContentType), action.ParentContentType)
};
Также не работает!
Я получаю исключение:
The argument 'value' was the wrong type. Expected 'Enums.ContentType'. Actual 'System.Object'.