Unable to get Azure TableEntity etag on CreateQuery

I make a query for entities from a table, changing them, and then perform a replace operation. The replacement operation failed because the etag property in etag is null. I checked, and etag is null when I get the object from the CreateQuery () call, but it populates when I do Retrieve (). Is there any way to get etag manually?

IEnumerable<MyEntity> query = from e in serviceContext.CreateQuery<MyEntity>(tableName) where e.Id == queryId select e; MyEntity entity = query.FirstOrDefault(); // Update the MyEntity object var replaceOperation = TableOperation.Replace(entity); MyCloudTableClient.GetTableReference(tableName).Execute(replaceOperation); // Exception is thrown here that eTag value is null 
+6
source share
2 answers

The problem is that you are mixing two different components.

 serviceContext.CreateQuery<MyEntity>(tableName) 

uses the System.Data.Services.Client namespace. In this model, the entity itself does not track etag; the context does this for you.

 MyCloudTableClient.GetTableReference(tableName).Execute(replaceOperation) 

Uses the Table.DataServices namespace. There is no central context in this model, and each object tracks its own state by exposing the Etag property. This is provided using the ITableEntity interface. The object you are using from the request is not intended to be used with newer libraries, and this is the root of the problem.

Switch to

 MyCloudTableClient.GetTableReference(tableName).CreateQuery<MyEntity>() 

to create your request, and your problems should disappear.

+1
source

Have you tried using TableQuery instead of DataServiceQuery?

So..

cloudTableClient.GetTableReference (TableName) .CreateQuery () instead of serviceContext.CreateQuery ..

btw TableQuery is new in 2.1, I think ...

+2
source

All Articles