【问题标题】:Delete Record from C# using ManagedInterop使用 ManagedInterop 从 C# 中删除记录
【发布时间】:2012-06-20 02:18:45
【问题描述】:

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

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(我不确定何时应该在其他)。

【问题讨论】:

    标签: c# dynamics-ax-2012


    【解决方案1】:

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

    在 X++ 方法中编写它可能更容易(并且更便于维护),只需从 C# 调用该方法。

    【讨论】:

    • 我会使用 X++,但这是部署代码,我了解到部署 X++ 代码充其量是一个混乱的过程。特别是当 AX 服务器上有自己的代码时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多