Enum as Key in RIA Services
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 =开发者_StackOverflow中文版 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!
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
精彩评论