开发者

templated object as POCO

In order to represent Enums in the edmx I am using wrapper:

This is the Enum:

public enum CompanyType
    {
        SMALL_BUSINESS,
        REGISTERED_BUSINESS,
        PROPRIETARY_LIMITED_COMPANY
    }

This is the wrapper:

public class CompanyTypeWrapper
{
    public CompanyType CompanyTypeEnum { get; set; }

    public string CompanyTypeName
    {
        get
    开发者_开发知识库    {
            return Enum.GetName(typeof(CompanyType), CompanyTypeEnum);
        }
        set
        {
            if (Enum.IsDefined(typeof(CompanyType), value))
            {
                CompanyTypeEnum = (CompanyType)Enum.Parse(typeof(CompanyType), value);
            }
        }
    }

    public static implicit operator CompanyTypeWrapper(CompanyType t)
    {
        return new CompanyTypeWrapper() { CompanyTypeEnum = t };
    }

    public static implicit operator CompanyType(CompanyTypeWrapper tw)
    {
        if (tw == null) return CompanyType.SMALL_BUSINESS;
        else return tw.CompanyTypeEnum;
    }
}

CompanyTypeName property has the code of the enum that comes from the database. CompanyTypeWrapper is the POCO object used to hold the enum value from database. Because I have a lot of enum - can I use templated EnumWrapper ? so that in the edmx the POCO object use to hold the enum value will be template? if yes - how should I call the name of the entity? CompanyType will be represented by EnumWrapper - is it possible?


I think this question already appeared on Stack Overflow and the answer was no. EDMX doesn't support templates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜