枚举作为 RIA 服务的关键
在我的实体类中,我使用枚举作为关键属性:
[DataContract]
public class MultimediaType
{
[DataMember]
[Key]
public Identificator Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataContract]
public enum Identificator
{
[EnumMember]
Image = 1,
[EnumMember]
Video = 2,
[EnumMember]
Sound = 3
}
}
[EnableClientAccess()]
public class DomService : DomainService
{
List<MultimediaType> _multimediaTypes = new List<MultimediaType>()
{
new MultimediaType()
{
Id = MultimediaType.Identificator.Image,
Name = "Image",
Description = "This is type for all images."
},
new MultimediaType()
{
Id = MultimediaType.Identificator.Video,
Name = "Video",
Description = "This is type for all videos."
},
new MultimediaType()
{
Id = MultimediaType.Identificator.Sound,
Name = "Sound",
Description = "This is type for all sounds."
},
};
[Query]
public IQueryable<MultimediaType> GetMultimediaTypes()
{
return _multimediaTypes.AsQueryable();
}
}
我的客户端是使用我的域服务的 SilverLight 应用程序。
我不知道出了什么问题,但我收到此错误:
属性“MultimediaType.Id”被标记为关键属性,但它不可序列化。您是否缺少 DataMemberAttribute?
你知道我做错了什么吗?多谢!
In my entity class i use enum as a key property:
[DataContract]
public class MultimediaType
{
[DataMember]
[Key]
public Identificator Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
[DataContract]
public enum Identificator
{
[EnumMember]
Image = 1,
[EnumMember]
Video = 2,
[EnumMember]
Sound = 3
}
}
[EnableClientAccess()]
public class DomService : DomainService
{
List<MultimediaType> _multimediaTypes = new List<MultimediaType>()
{
new MultimediaType()
{
Id = MultimediaType.Identificator.Image,
Name = "Image",
Description = "This is type for all images."
},
new MultimediaType()
{
Id = MultimediaType.Identificator.Video,
Name = "Video",
Description = "This is type for all videos."
},
new MultimediaType()
{
Id = MultimediaType.Identificator.Sound,
Name = "Sound",
Description = "This is type for all sounds."
},
};
[Query]
public IQueryable<MultimediaType> GetMultimediaTypes()
{
return _multimediaTypes.AsQueryable();
}
}
My client is SilverLight application that consume my domain service.
I have no idea what is wrong, but i obtaint this error:
The property 'MultimediaType.Id' is marked as a key property, but it's not serializable. Are you missing DataMemberAttribute?
Do you have any idea what i do wrong? Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EnumMemberAttribute :指定该字段是枚举成员并且应该序列化。
检查以下链接:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.enummemberattribute(v=vs.95).aspx
与 WCF 服务共享枚举
另请参阅备注和示例
EnumMemberAttribute : Specifies that the field is an enumeration member and should be serialized.
Check the below lins :
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.enummemberattribute(v=vs.95).aspx
Sharing Enum with WCF Service
Also take a look at the Remarks and Example