2012-06-18 44 views
3

我正在使用使用dll Microsoft.Dynamics.AX.ManagedInterop与AX 2012环境一起工作的C#项目。从代码中,我需要根据特定条件查找SalesQuotationLine并将其删除。到目前为止,我可以获得我需要的记录,但我无法删除它,因为我没有使用TTSBEGIN/TTSCOMMI T语句,而且我也没有使用FORUPDATE。这是我的代码:使用ManagedInterop从C#中删除记录

DictTable dictTable = new DictTable(Global.tableName2Id("SalesQuotationLine")); 
int quotationIdFieldId = (int)dictTable.Call("fieldName2Id", "QuotationId"); 
int bdcParentRecIdFieldId = (int)dictTable.Call("fieldName2Id", "BDCParentRecId"); 

var query = new Query(); 
var datasource = query.addDataSource(Global.tableName2Id("SalesQuotationLine")); 
var queryRange1 = datasource.addRange(quotationIdFieldId); 
queryRange1.value = "=" + line.QuotationId;    

QueryRun queryRun = new QueryRun(query as object); 
while (queryRun.next()) 
{ 
    var result = queryRun.get(Global.tableName2Id("SalesQuotationLine")); 
    result.Delete(); 
} 

我也看了一下代码在这里,http://msdn.microsoft.com/en-us/library/cc197113.aspx但我发现,因为我一起工作的代码不使用.NET Business Connector的,我不能用它(我不知道什么时候一个DLL应该用于其他)。

回答

2

在Microsoft.Dynamics.AX.ManagedInterop.RuntimeContext.Current上使用TTSBegin()TTSCommit()方法。 forUpdate标志可以通过QueryBuildDataSource的update()进行设置。

将它写入X ++方法中调用C#中的方法可能更容易(也更好维护)。

+0

我会使用X ++,但这是部署代码,并且我已经了解到部署X ++代码在最好的过程中是一个混乱的过程。特别是当AX服务器上有自己的代码时。 –