Get the 'Nullable' state programmatically of a Property in Entity Framework

后端 未结 2 700
春和景丽
春和景丽 2021-01-26 08:32

I need to get the Nullable property out for a field in EF. Some magic code needs to be done on properties that are Nullable=True, and I cannot find a working solution to get the

2条回答
  •  别那么骄傲
    2021-01-26 08:54

    You can use Nullable.GetUnderlyingType Method for this

    if (Nullable.GetUnderlyingType(propertyType) != null)
    {
        // It's nullable
    }
    

提交回复
热议问题