[英]WEB Api not sending Enum to client
I have got one class "ApplicationSetting" inherited from "BaseSync" class which inherited from "BaseEntity" class. 我从“ BaseSync”类继承了一个类“ ApplicationSetting”,该类又从“ BaseEntity”类继承了。 Following is my class structure.
以下是我的课程结构。
[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; }
}
}
Now problem is that whenever i check my class json object in browser. 现在的问题是,每当我在浏览器中检查我的类json对象时。 I don't get my Enum property which is EntitySate?
我没有得到EntitySate的Enum属性? Any reason why?
有什么原因吗? I am getting all other property like SettingKey and Id but i'm not getting my Enum at all.
我正在获取所有其他属性,例如SettingKey和Id,但我根本没有获取Enum。
My enum class structure is mentioned below 我的枚举类结构如下
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
}
You need to define your ENUM as data contract. 您需要将ENUM定义为数据合同。
Some thing like following. 像下面的事情。
[DataContract(Name = "CarCondition")]
public enum CarConditionWithNumbers
{
[EnumMember]
New = 10,
[EnumMember]
Used = 20,
[EnumMember]
Rental = 30,
}
see following link. 请参阅以下链接。
http://msdn.microsoft.com/en-us/library/aa347875.aspx http://msdn.microsoft.com/en-us/library/aa347875.aspx
Also there few other examples also. 也有其他几个例子。
http://beyondrelational.com/modules/2/blogs/48/posts/10065/enumeration-in-datacontract-of-wcf.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 http://dotnetmentors.com/wcf-datacontract-with-enum-example.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.