Azure Table Storage - Updating to 3.0 causing DataServiceQuery Errors
Asked Answered
L

2

8

I recently updated the nuget package for Microsoft.WindowsAzure.Storage to the 3.0 package which also included updates to WCF Data Services Client and it's dependencies. Since the update I get an error when the query is resolving stating:

"There is a type mismatch between the client and the service. Type 'ShiftDigital.Flow.Data.RouteDiagnostic' is not an entity type, but the type in the response payload represents an entity type. Please ensure that types defined on the client match the data model of the service, or update the service reference on the client."

I've done nothing but update the packages and both my application along with a test script I setup in LinqPad generate this exception.

Here is the definition of the entity I've been returning just fine before the update

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);
        }
    }

Here is the code performing the query

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();

Has something changed that in the latest update or a different way to structure the entities when using data service queries?

Licentious answered 16/1, 2014 at 17:3 Comment(0)
L
12

Turns out with the update to WCF Data Services 5.6 I needed to add the following attribute to my type:

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

Once I added the DataServiceKey attribute, all was well again.

Licentious answered 16/1, 2014 at 19:14 Comment(3)
Thank you - I upgraded one of my project's libraries this morning and ran into this same issue.Essary
Took me a while to figure out that this resides in System.Data.Services.Common in the Microsoft.Data.Services.Client DLL.Doley
I had the same problem with a [DataServiceKey("ID") annotation where the property was actually named IdBranca
I
2

When using WCF Data Services, please make your class inherit from TableServiceEntity rather than TableEntity, which already has the DataServiceKey attribute defined. TableEntity is used for the new Table Service Layer in the Windows Azure Storage Client Library. For more information on the new Table Service Layer, please see our blog post.

Incompliant answered 16/1, 2014 at 21:48 Comment(2)
I don't always want to use my type just with data services. I also want it to be a usable with the Table Service Layer. If I inherit from TableServiceEntity would I still be able to use the type with Table Service Layer?Licentious
Unfortunately, that is not a supported scenario. If you already started using the Table Service Layer, however, I would encourage completely switching to it.Incompliant

© 2022 - 2024 — McMap. All rights reserved.