我有一个继承自“BaseSync”类继承自“BaseEntity”类的“ApplicationSetting”类。 以下是我的班级结构。
[DataContract(Namespace = HelpersServiceModel.DefaultUriNamespace)]
public class ApplicationSetting : BaseSyncEntity
{
[DataMember]
public string SettingKey { get; set; }
}
[DataContract(Namespace = HelpersServiceModel.DefaultUriNamespace)]
public abstract class BaseSyncEntity : BaseEntity
{
}
[DataContract(Namespace = HelpersServiceModel.DefaultUriNamespace)]
public abstract class BaseEntity : ICloneable, IComparable, IEntityState, INotifyPropertyChanged, IDataErrorInfo
{
[DataMember(EmitDefaultValue = false)]
public Nullable<int> Id
{
get
{
return _id;
}
set
{
SetProperty(ref _id, value);
}
}
[DataMember(EmitDefaultValue = false)]
public EntityState EntityState
{
get { return _entityState; }
set { _entityState = value; }
}
}
现在的问题是每当我在浏览器中检查我的类json对象时。我不知道我的Enum属性是EntitySate吗?有什么理由吗?我得到了像SettingKey和Id这样的所有其他财产,但我根本没有得到我的Enum。
我的枚举类结构如下所述
public enum EntityState
{
/// <summary>
/// The Business Entity is unchanged and no action needs to be taken on it.
/// </summary>
Unchanged,
/// <summary>
/// The Business Entity has been created and has not been inserted into the database.
/// </summary>
Added,
/// <summary>
/// The Business Entity has been changed and requires updating in the database.
/// </summary>
Changed,
/// <summary>
/// The Business Entity has been marked for removal from the database.
/// </summary>
Removed
}
答案 0 :(得分:0)
您需要将ENUM定义为数据合约。
有些事情如下。
[DataContract(Name = "CarCondition")]
public enum CarConditionWithNumbers
{
[EnumMember]
New = 10,
[EnumMember]
Used = 20,
[EnumMember]
Rental = 30,
}
请参阅以下链接。
http://msdn.microsoft.com/en-us/library/aa347875.aspx
此外,还有其他一些例子。
http://beyondrelational.com/modules/2/blogs/48/posts/10065/enumeration-in-datacontract-of-wcf.aspx
http://dotnetmentors.com/wcf-datacontract-with-enum-example.aspx