我有一个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);
我希望从数据集中打印leadource的指定值,但不输出任何内容。
答案 0 :(得分:2)
从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);
}