枚举作为 RIA 服务的关键

发布于 2024-10-16 02:32:56 字数 1496 浏览 2 评论 0原文

在我的实体类中,我使用枚举作为关键属性:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-10-23 02:32:56

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文