"Fluent methods may not be invoked on a Query created via CloudTable.CreateQuery<T>()" exception

StackOverflow https://stackoverflow.com/questions/21484694

  •  05-10-2022
  •  | 
  •  

Frage

What does the following exception means?

System.NotSupportedException was unhandled Message: An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll Additional information: Fluent methods may not be invoked on a Query created via CloudTable.CreateQuery()

It does not show the code throwing the exception so I don't know how to start debugging it.

Result StackTrace: at System.Web.Http.ApiController.d__1.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at TestFramework.ExecuteRequest(HttpRequestMessage request) in d:\ at TestFramework.Post(String uri, Object tniObject) in d:\ at TestFramework.PostCall(String uri, Object o) in d:\ at TestFramework.MyMethod(String one, String two, MyStruct three) in d:\ ... (Removed for privacy)

I believe the problem is in the following instruction.

string queryString = TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, myId),
                                               TableOperators.And,
                                               TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, number));
var theQuery = MyTable.CreateQuery<MyEntity>().Where(queryString);

can I use theQuery then to perform a segmented async query?

var returnList = new List<T>();
TableQuerySegment<T> querySegment = null;

querySegment = await theQuery.AsTableQuery().ExecuteSegmentedAsync(null);

// The query could potentially return more than one object
returnList.AddRange(querySegment);

Well, changing the CreateQuery method call to the following code made the exception to go away.

 var query = new TableQuery<TenantTNEntity>().Where(queryString);

The exception I get now says:

Result Message: Test method MyMethod threw exception:

System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Unknown Table. The TableQuery does not have an associated CloudTable Reference. Please execute the query via the CloudTable ExecuteQuery APIs.

War es hilfreich?

Lösung

I don't know if this is specifically your problem, but it certainly was mine, and it took me a while to figure out. For reasons that I'm not entirely clear on, the Azure team has provided two different and incompatible ways to execute queries - and although they're incompatible at runtime, the Azure team has helpfully (not!) made sure that they have compatible signatures at compile time.

See the difference between the "Fluent" and "IQueryable" modes described here:

http://blogs.msdn.com/b/windowsazurestorage/archive/2013/09/07/announcing-storage-client-library-2-1-rtm.aspx

In other words, both of these will compile and run and do more or less the same thing:

var fluentQuery = new TableQuery<T>().Where(filter);
var fluentResult = Table.ExecuteQuery(fluentQuery);

var iQueryableQuery= from ent in Table.CreateQuery<T>() 
                     where ent.PartitionKey == "some value" 
                     select ent;
var iQueryableResult = iQueryableQuery.AsTableQuery().Execute();

But while this one will compile just fine, it will blow up at runtime with the System.NotSupportedException that you (and I) ran into.

var fluentQuery2 = Table.CreateQuery<T>().Where(filter);
var fluentResult2 = fluentQuery2.Execute();

I'm sure that the folks at MS had some good reason for this particular violation of the Principle of Least Astonishment - they're not idiots - but it certainly remains the case that this behavior is, shall we say, unusual.

Andere Tipps

Adding ".AsQueryable()" before ".Take(x)" will make it run

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top