Azure表存储拒绝具有其值为接口的Property的实体

时间:2012-10-05 21:26:38

标签: azure azure-storage azure-table-storage

我有一个名为“Comment”的类型,我将其保存到Azure Table Storage。由于注释可以是任何数量的其他类型,我创建了一个所有这些类型实现的接口,然后在注释上放置ICommentable类型的属性。因此,Comment有一个名为About of type ICommentable的属性。

当我尝试将注释保存到Azure表存储时,如果Comment.About属性有值,我会得到毫无价值的无效输入错误。但是,如果Comment.About没有值,我没有问题。为什么会这样?

Comment.About不是唯一属性是引用类型。例如,Comment.From是引用类型,但Comment.About是作为接口的类型的唯一属性。

失败:

var comment = new Comment();
        comment.CommentText = "It fails!";
        comment.PartitionKey = "TEST";
        comment.RowKey = "TEST123";
        comment.About = sow1;
        comment.From = person1;

使用:

var comment = new Comment();
        comment.CommentText = "It works!";
        comment.PartitionKey = "TEST";
        comment.RowKey = "TEST123";
        //comment.About = sow1;
        comment.From = person1;

谢谢!

2 个答案:

答案 0 :(得分:2)

Windows Azure表存储只能存储少数几种类型,其中没有一种是您创建的ICommentable类型:http://msdn.microsoft.com/en-us/library/windowsazure/dd179338.aspx

答案 1 :(得分:1)

Azure表存储客户端不支持控制哪些属性可持久的精细方法。

您可能希望查看我在CodePlex上的开源项目,该项目允许精细控制哪些字段/属性持久存储到表存储以及如何序列化它们。 (http://lucifurestash.codeplex.com/

编辑:修正了拼写错误+澄清。