查询Azure表存储在Azure函数中,然后插入Dynamics CRM中



我有一个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的指定值,但没有输出。

从Azure表中检索数据需要Azure工具,或者至少需要存储SDK,以及一些命令,从Microsoft的文档中获取:

// 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);
}

相关内容

最新更新