EF 4.1 Code First - map enum wrapper as complex type

后端 未结 4 1252
误落风尘
误落风尘 2020-12-24 08:25

I\'m trying to build a generic solution to the problem of enums with EF 4.1. My solution is basically a generic version of How to fake enums in ef 4. The enum wrapper class

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 09:24

    based on Henrik Stenbæk answer. assigning is working fine

    category.ChildSortType = CategorySort.AlphabeticOrder
    

    but comparing the wrapper to its enum doesn't work.

    if(category.ChildSortType == CategorySort.AlphabeticOrder)
    {
    
    }
    

    the following operator should be added to the abstract class

    public static implicit operator TEnum(EnumWrapper w)
            {
                if (w == null)
                    return default(TEnum);
                else
                    return w.EnumVal;
            }
    

提交回复
热议问题