TARGET: 创建控制台应用程序,1)从Azure Data Lake Store读取json 2)以json的形式将数据存储到Cosmos DB。
问题: 我可以读取文件(1),但不能将数据存储到Cosmos。看错误。
错误: 严重性代码描述项目文件行抑制状态 错误CS1061'AdlsClient'不包含'CreateDocumentAsync'的定义,并且找不到接受类型'AdlsClient'的第一个参数的扩展方法'CreateDocumentAsync'(您是否缺少using指令或程序集引用?)CircleCustomActivityCosmosDB C:\ AzureCoding \ CustomActivityCosmosDB \ Program.cs
CODE:
private async Task CreateDocumentsAsync()
{
string fileName = "/myjsonfile.json";
// Obtain AAD token for ADLS
var creds = new ClientCredential(applicationId, clientSecret);
var clientCreds = ApplicationTokenProvider.LoginSilentAsync(tenantId, creds).GetAwaiter().GetResult();
// Create ADLS client object
AdlsClient client = AdlsClient.CreateClient(adlsAccountFQDN, clientCreds);
String json = "";
//Read file contents
using (var readStream = new StreamReader(client.GetReadStream(fileName)))
{
string line;
while ((line = readStream.ReadLine()) != null)
{
Console.WriteLine("Read file Line: " + line);
json += line;
}
}
//Read file to json
JsonTextReader reader = new JsonTextReader(new StringReader(json));
//Storing json to CosmosDB
Uri collectionUri = UriFactory.CreateDocumentCollectionUri(databaseName, collectionName);
//ERROR HAPPENS HERE - 'AdlsClient' does not contain a definition for 'CreateDocumentAsync' and no extension method 'CreateDocumentAsync'
await client.CreateDocumentAsync(collectionUri, reader);
}
}
答案 0 :(得分:0)
没有为班级<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody id='body'>
</tbody>
<table>
定义CreateDocumentAsync
方法,请参阅the docs
您需要一个CosmosDB客户端在那里创建文档,我想您想要使用DocumentClient.CreateDocument。
AdlsClient
类仅提供访问Azure Data Lake Store的方法,而不是CosmosDB数据存储区。为此,您需要AdlsClient
课程,请参阅the docs。
总结如下:
TARGET:创建控制台应用程序,1)从Azure Data Lake Store读取json 2)以json的形式将数据存储到Cosmos DB。
1)你需要AdlsClient(访问adls)
for 2)你需要DocumentClient(访问cosmosdb)