简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM