我有以下存储过程,只能通过id找到一个对象.
function sample(id) { var context = getContext(); var response = context.getResponse(); var collection = context.getCollection(); var findObject = "SELECT * FROM Objects o where o.userId='" + id +"'"; // Query documents and take 1st item. var isAccepted = collection.queryDocuments( collection.getSelfLink(),findObject,function (err,Feed,options) { if (err) throw err; // Check the Feed and if empty,set the body to 'no docs found',// else take 1st element from Feed if (!Feed || !Feed.length) throw new Error("Object not found"); else response.setBody(Feed[0]); }); if (!isAccepted) throw new Error('The query was not accepted by the server.'); }
这是扩展Document的C#类
public class UserPoints: Document { [JsonProperty("userId")] public Guid UserId; [JsonProperty("remainingPoints")] public int RemainingPoints; }
在我的main函数中,我调用上面的存储过程并期望它返回UserId的UserPoints对象.
例如:
UserPoints points = new UserPoints() { UserId = Guid.NewGuid(),RemainingPoints = 1000 }; await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName,collection),points); points.Dump(); var response = await client.ExecuteStoredProcedureAsync<UserPoints>(UriFactory.CreateStoredProcedureUri(databaseName,collection,storedProcedureName),points.UserId.ToString()); response.Response.Dump();
我得到以下异常当我执行存储过程时,无法将“Microsoft.Azure.Documents.Document”类型的对象强制转换为“UserPoints”类型
如果我只是停止扩展Document基类,那么一切正常,但是我无法访问更新所需的SelfLink属性.难道我做错了什么?如果ExecuteStoredProcedureAsync采用强类型,它不应该能够键入强制类型并返回该类型的对象吗?