我想创建一个复杂的用户定义的 AIF 查询服务,方法是使用 Visual Studio 并用 C# 编写查询服务的代码。我正在使用两个自定义表,其中一个是标题,一个是行表。我通过使用两个表在查询中添加了字段,并应用了适当的范围,它工作正常。现在我想在这两个表之间建立一个关系,这样我就可以根据关系获取数据。
请帮助我了解如何在 AIF 查询服务中的多个表之间建立关系。
query.DataSources = new QueryDataSourceMetadata[2];
query.Name = "AXCustomerInfo";
QueryDataSourceMetadata custTableDS = new QueryDataSourceMetadata();
custTableDS.Name = "CustTable";
custTableDS.Table = "CustTable";
custTableDS.Enabled = true;
query.DataSources[0] = custTableDS;
custTableDS.DynamicFieldList = false;
custTableDS.Fields = new QueryDataFieldMetadata[1];
QueryDataFieldMetadata accountNum;
accountNum = new QueryDataFieldMetadata();
accountNum.FieldName = "AccountNum";
accountNum.SelectionField = SelectionField.Database;
custTableDS.Fields[0] = accountNum;
custTableDS.HasRelations = true;
custTableDS.JoinMode =JoinMode.InnerJoin;
QueryDataSourceMetadata dirPartyTableDS = new QueryDataSourceMetadata();
dirPartyTableDS.Name = "DirPartyTable";
dirPartyTableDS.Table = "DirPartyTable";
dirPartyTableDS.Enabled = true;
query.DataSources[1] = dirPartyTableDS;
dirPartyTableDS.DynamicFieldList = false;
dirPartyTableDS.Fields = new QueryDataFieldMetadata[1];
QueryDataFieldMetadata name;
name = new QueryDataFieldMetadata();
name.FieldName = "Name";
name.SelectionField = SelectionField.Database;
dirPartyTableDS.Fields[0] = name;
dirPartyTableDS.HasRelations = false;
result = client.ExecuteQuery(query, ref paging);
foreach (DataRow row in result.Tables[0].Rows)
{
Console.WriteLine(String.Format("{0}", row[0]));
foreach (DataRow row1 in result.Tables[1].Rows)
{
Console.WriteLine(String.Format("{0}", row1[0]));
}
}