Mapping Nullable Enum to database int field that allows null

Skip to first unread message


Aug 27, 2021, 2:35:50 PM8/27/21
to nhusers

.net, C#
How can I map Nullable Enum property on an entity to database int field that allows null?

I have this but it doesn't work:
<property name="ItemType" type="Int32" column="ItemType" not-null="false" />

When the entity is queried/being hydrated, it will throw:
Invalid Cast (check your mapping for property type mismatches); setter of PrlSystems.AccountingLibrary.Model.Item

Interestingly, if the ItemType property would not be nullable type, this mapping works fine.
Also, I am using nullables for DateTime, and other build in types, and it works fine. I just map these to their corresponding types.
Reply all
Reply to author
0 new messages