【问题标题】:Azure Table Storage - Updating to 3.0 causing DataServiceQuery ErrorsAzure 表存储 - 更新到 3.0 导致 DataServiceQuery 错误
【发布时间】:2014-02-05 17:39:07
【问题描述】:

我最近将 Microsoft.WindowsAzure.Storage 的 nuget 包更新为 3.0 包,其中还包括对 WCF 数据服务客户端及其依赖项的更新。自更新以来,当查询解析时出现错误:

“客户端和服务之间存在类型不匹配。类型 'ShiftDigital.Flow.Data.RouteDiagnostic' 不是实体类型,而是 响应负载中的类型表示实体类型。请 确保客户端上定义的类型与客户端的数据模型相匹配 服务,或更新客户端上的服务引用。”

除了更新包之外我什么都没做,我的应用程序以及我在 LinqPad 中设置的测试脚本都会生成此异常。

这是我在更新之前返回的实体的定义

public class RouteDiagnostic : TableEntity
    {
        public long? LeadRecipientRouteId { get; set; }
        public bool Successful { get; set; }
        public int Duration { get; set; }
        public string Request { get; set; }
        public string Response { get; set; }

        public RouteDiagnostic()
            : base()
        {
            this.Timestamp = DateTimeOffset.Now;
            this.PartitionKey = GetPartitionKey(this.Timestamp.Date);
            this.RowKey = Guid.NewGuid().ToString();
        }

        public static string GetPartitionKey(DateTime? keyDateTime = null)
        {
            return string.Format("{0:yyyyyMM}", keyDateTime ?? DateTime.Now);
        }
    }

这是执行查询的代码

var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("...");
var tableClient = storageAccount.CreateCloudTableClient();

var tableContext = new Microsoft.WindowsAzure.Storage.Table.DataServices.TableServiceContext(tableClient);

var diagnostics =
        tableContext.CreateQuery<RouteDiagnostic>("RouteDiagnostic")
        .Where(rd => rd.PartitionKey == "0201401")
        .ToList();

在使用数据服务查询时,在最新更新中或以不同的方式构造实体是否发生了某些变化?

【问题讨论】:

    标签: azure wcf-data-services azure-storage azure-table-storage


    【解决方案1】:

    随着 WCF 数据服务 5.6 的更新,我需要将以下属性添加到我的类型中:

    [DataServiceKey("PartitionKey", "RowKey")]
    

    添加 DataServiceKey 属性后,一切都恢复正常了。

    【讨论】:

    • 谢谢 - 我今天早上升级了我项目的一个库并遇到了同样的问题。
    • 花了我一段时间才发现它位于System.Data.Services.CommonMicrosoft.Data.Services.Client DLL 中。
    • 我在 [DataServiceKey("ID") 注释中遇到了同样的问题,其中属性实际上被命名为 Id
    【解决方案2】:

    使用 WCF 数据服务时,请让您的类继承自 TableServiceEntity 而不是 TableEntity,后者已经定义了 DataServiceKey 属性。 TableEntity 用于 Windows Azure 存储客户端库中的新表服务层。有关新表服务层的更多信息,请参阅我们的blog post

    【讨论】:

    • 我并不总是想将我的类型仅用于数据服务。我还希望它可以与表服务层一起使用。如果我从 TableServiceEntity 继承,我仍然可以将类型与表服务层一起使用吗?
    • 很遗憾,这不是受支持的方案。但是,如果您已经开始使用表服务层,我建议您完全切换到它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多