Dynamics AX 2012 QueryService通过C# - 关系和JOINMODE用法[英] Example for Dynamics AX 2012 QueryService through C# - Relations and JoinMode usage

本文是小编为大家收集整理的关于Dynamics AX 2012 QueryService通过C# - 关系和JOINMODE用法的处理方法,想解了Dynamics AX 2012 QueryService通过C# - 关系和JOINMODE用法的问题怎么解决?Dynamics AX 2012 QueryService通过C# - 关系和JOINMODE用法问题的解决办法?Dynamics AX 2012 QueryService通过C# - 关系和JOINMODE用法问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

尝试通过C#应用程序访问AX 2012 QueryService,并希望仅获取客户ID和自定义字段.问题是,CustomerId在CustTable中,并且自定义名称在DirPartyTable中.

对文章或代码样本的任何帮助将不胜感激.

  1. 引用querydatasourcemetadata将加入在这些表中并获取数据.
  2. 有什么选择以及何时使用关系和JoinMode?

我在MSDN中进行了搜索,它只是列出了属性名称和方法,而对代码示例的形式没有太大帮助.

推荐答案

根据我的知识,您将要查询的两个表放入QueryDataSourCemetadata中.结果数据集应包含两个表. (用于创建QueryDataSourCemetAdataObject的示例代码在这里: http://msdn.microsoft.com/en-us/en-us/library/library/library/gg8444682.aspx )

您需要加入的表格的属性是returnflatdataset. (这可能会有所帮助: http://msdn.microsoft.com/en-en-en-us/库/gg841671.aspx )

希望我能帮助您或指向您正确的方向!

其他推荐答案

为时已晚,无法回答,我认为您可能已经找到了一些解决方案.无论如何,这是我对AX社区的回答的链接:

https://community.dynamics.com/ax/F/33/P/212065/573674#573674


我找到了2种添加C#关系的方法.我已经根据AOT表关系评论了第一种方法.在下面的代码中,queryservicReference是vs中的服务参考名称.如果您只有QueryService参考,则可以在所有行中删除它,但没有MetadatAservice参考.这是代码:

query.DataSources = new QueryServiceReference.QueryDataSourceMetadata[1];

// Set the properties on Customers data source.
 customerDataSource = new QueryServiceReference.QueryDataSourceMetadata();
 customerDataSource.Name = "Customers";
 customerDataSource.Enabled = true;
 customerDataSource.FetchMode = QueryServiceReference.FetchMode.OneToOne;
 customerDataSource.Table = "CustTable";
 //customerDataSource.DynamicFieldList = false;

query.DataSources[0] = customerDataSource;


 QueryServiceReference.QueryDataSourceMetadata dirPartyTableDataSource = new QueryServiceReference.QueryDataSourceMetadata();
 dirPartyTableDataSource.Name = "DirPartyTable";
 dirPartyTableDataSource.Table = "DirPartyTable";
 dirPartyTableDataSource.Enabled = true;
 dirPartyTableDataSource.DynamicFieldList = true;


 customerDataSource.DataSources = new QueryServiceReference.QueryDataSourceMetadata[1] { dirPartyTableDataSource };
 QueryServiceReference.QueryRelationMetadata relation = new QueryServiceReference.QueryRelationMetadata();

 //this is also one way of setting the relation 
 //relation.JoinRelation = "DirPartyTable_FK"; //table relation defined in AOT
 //relation.JoinDataSource = customerDataSource.Name; //parent datasource name

relation.Table = "CustTable";//Parent table
 relation.Field = "Party"; 
 relation.RelatedTable = "DirPartyTable"; // child table
 relation.RelatedField = "RecId";
 relation.JoinDataSource = customerDataSource.Name; 
 dirPartyTableDataSource.Relations = new QueryServiceReference.QueryRelationMetadata[1] { relation };

本文地址:https://www.itbaoku.cn/post/1957688.html

问题描述

Trying to access AX 2012 QueryService through c# application and would like to get CustomerID and Customername fields only. Problem is, CustomerID is in CustTable and CustomerName is in DirPartyTable.

Any help to article or code samples would be appreciated.

  1. Reference to QueryDataSourceMetadata to put join in these tables and get data.
  2. What are the options and when to use Relations and JoinMode?

I searched in MSDN and it just lists the property names and methods and not much help in the form of code samples.

推荐答案

According to my knowledge, you put in the two tables you want to query into your QueryDataSourceMetadata. The resulting dataset should contain both tables. (Example code for creating a QueryDataSourceMetadataObject is here: http://msdn.microsoft.com/EN-US/library/gg844682.aspx)

The property you need, for the tables to be joined, is ReturnFlatDataSet. (this may help: http://msdn.microsoft.com/EN-US/library/gg841671.aspx)

Hope i could help you or point you in the right direction!

其他推荐答案

Its too late to answer and I think you already might have found some solutions. Anyway here is the link to my response on AX community:

https://community.dynamics.com/ax/f/33/p/212065/573674#573674


I found 2 ways to add the relations from c#. I have commented the first approach based on AOT table relation. In the code below QueryServiceReference is the service reference name in VS. You can remove it in all the lines if you have only QueryService reference but no MetaDataService reference. Here is the code :

query.DataSources = new QueryServiceReference.QueryDataSourceMetadata[1];

// Set the properties on Customers data source.
 customerDataSource = new QueryServiceReference.QueryDataSourceMetadata();
 customerDataSource.Name = "Customers";
 customerDataSource.Enabled = true;
 customerDataSource.FetchMode = QueryServiceReference.FetchMode.OneToOne;
 customerDataSource.Table = "CustTable";
 //customerDataSource.DynamicFieldList = false;

query.DataSources[0] = customerDataSource;


 QueryServiceReference.QueryDataSourceMetadata dirPartyTableDataSource = new QueryServiceReference.QueryDataSourceMetadata();
 dirPartyTableDataSource.Name = "DirPartyTable";
 dirPartyTableDataSource.Table = "DirPartyTable";
 dirPartyTableDataSource.Enabled = true;
 dirPartyTableDataSource.DynamicFieldList = true;


 customerDataSource.DataSources = new QueryServiceReference.QueryDataSourceMetadata[1] { dirPartyTableDataSource };
 QueryServiceReference.QueryRelationMetadata relation = new QueryServiceReference.QueryRelationMetadata();

 //this is also one way of setting the relation 
 //relation.JoinRelation = "DirPartyTable_FK"; //table relation defined in AOT
 //relation.JoinDataSource = customerDataSource.Name; //parent datasource name

relation.Table = "CustTable";//Parent table
 relation.Field = "Party"; 
 relation.RelatedTable = "DirPartyTable"; // child table
 relation.RelatedField = "RecId";
 relation.JoinDataSource = customerDataSource.Name; 
 dirPartyTableDataSource.Relations = new QueryServiceReference.QueryRelationMetadata[1] { relation };
查看更多