【问题标题】:Query Azure table storage in an azure function and insert into Dynamics CRM在 azure 函数中查询 Azure 表存储并插入 Dynamics CRM
【发布时间】:2017-09-08 13:32:22
【问题描述】:

我有一个 azure 函数,我想从 Azure 表中获取数据,然后将其推送到 CRM。在 CRM 中创建记录很容易,但我不确定如何正确访问表格。

using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;

public static void Run(TimerInfo myTimer, Lead lead, TraceWriter log)
{
    var connectionString = "AuthType=Office365;Username=*****; Password=****;Url=*****";
CrmConnection connection = CrmConnection.Parse(connectionString);
using (OrganizationService orgService = new OrganizationService(connection))
{
try
{
    var query = new QueryExpression("account");
    query.ColumnSet.AddColumns("name");
    var ec = orgService.RetrieveMultiple(query);
    log.Verbose(ec[0].GetAttributeValue<string>("name"));
    Lead lead = new Lead();
    string name = lead.LeadSource;
    Console.WriteLine("name is: {0}", name);
    //log.Verbose($"Name in Person entity: {lead.Name}");
}
    catch (ArgumentNullException e)
    {
        Console.WriteLine("{0} First exception caught.", e);
    }
  }
}


public class Lead 
{
public string PartitionKey {get; set;}
public string RowKey { get; set; }
public string Name { get; set; }
public string ProductId {get; set;}
public string CustomerInfo {get; set;}
public string LeadSource {get; set;}
public string ActionCode {get; set;}
public string PublisherDisplayName {get; set;}
public string OfferDisplayName {get; set;}
public string CreatedTime {get; set;}
public string Description {get; set;}
} 

在行中:

Lead lead = new Lead();
string name = lead.LeadSource;
Console.WriteLine("name is: {0}", name);

我希望从数据集中打印leadsource 的指定值,但它什么也不输出。

【问题讨论】:

    标签: c# azure dynamics-crm azure-storage azure-functions


    【解决方案1】:

    从 Azure 表中检索数据需要 Azure Tools,或者至少是 Storage SDK,以及一些取自 Microsoft's documentation 的命令:

    // Retrieve the storage account from the connection string.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("StorageConnectionString"));
    
    // Create the table client.
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    
    // Create the CloudTable object that represents the "people" table.
    CloudTable table = tableClient.GetTableReference("people");
    
    // Construct the query operation for all customer entities where PartitionKey="Smith".
    TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"));
    
    // Print the fields for each customer.
    foreach (CustomerEntity entity in table.ExecuteQuery(query))
    {
        Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
            entity.Email, entity.PhoneNumber);
    }
    

    【讨论】:

    • 我读过你应该在从 Azure 函数查询 CosmosDB 时使用单例。你需要用 CloudTableClient 来做吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多