[英]templated object as POCO
In order to represent Enums in the edmx I am using wrapper: 为了在edmx中表示枚举,我使用包装器:
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. CompanyTypeName属性具有来自数据库的枚举的代码。 CompanyTypeWrapper is the POCO object used to hold the enum value from database.
CompanyTypeWrapper是POCO对象,用于保存数据库中的枚举值。 Because I have a lot of enum - can I use templated EnumWrapper ?
因为我有很多枚举-我可以使用模板化的EnumWrapper吗? so that in the edmx the POCO object use to hold the enum value will be template?
这样在edmx中用来保存枚举值的POCO对象将是模板? if yes - how should I call the name of the entity?
如果是,我该如何称呼实体名称? CompanyType will be represented by EnumWrapper - is it possible?
CompanyType将由EnumWrapper表示-有可能吗?
I think this question already appeared on Stack Overflow and the answer was no. 我认为这个问题已经出现在Stack Overflow上,答案是否定的。 EDMX doesn't support templates.
EDMX不支持模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.