I have the following statement:
select new Action {
ParentContentType = action.ParentContentType != null ? (ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType) : null
};
ParentContentType is a nullable enum of type ContentType
action.ParentContentType maps to a database table which is a nullable int.
If action.ParentContentType isnt null, I determine the enum value using:
(ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType)
In the case of when action.ParentContentType IS null I try to set the nullable enum to the value null.
This doesnt compile and I get:
Error 1 Type of conditional expression cannot be determined because there is no implicit conversion between ContentType' and '<null>'
EDIT
I could create a null enum value.. ie ContentType.EMPTY.
However:
ParentContentType = action.ParentContentType == null ? ContentType.EMPTY : (ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType) };
Doesnt work either!
I get the exception:
The argument 'value' was the wrong type. Expected 'Enums.ContentType'. Actual 'System.Object'.