0

假设我需要得到AOT objects属于model

  • 例如表对象
  • 我需要TablesTable Extensions
  • 结果对象可以是treeNodeDictTable

问题:如何从模型中获取 AOT 对象...

  1. X++?
  2. T-SQL?
  3. C#代码?

谢谢。


例如:有一个型号名称Fleet Management Extension。我可以使用 Visual Studio 获取对象。如何从 x++、t-sql、c# 中获取这些对象?

在此处输入图像描述


我当前的 x++ 代码。太可怕了。

protected set getTableNamesFromModels()
{
    boolean inModel(str modelDisplayName, str objname, System.Type type)
    {
        var models = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetModelsOfMetadataArtifact(objName, type);
        var modelsEnumerator = models.getEnumerator();
        while (modelsEnumerator.moveNext())
        {
            Microsoft.Dynamics.AX.Metadata.MetaModel.ModelInfo modelInfo = modelsEnumerator.Current;
            if( ModelDisplayName == modelInfo.DisplayName )
            {
                return true;
            }
        }

        return false;
    }

    set result = new set(Types::String);
    var modelName = 'Fleet Management Extension';

    var axTableType = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxTable();
    var axTableExtType = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxTableExtension();

    var t = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::TableNames();  // Why Enumerator?
    while ( t.moveNext() )
    {
        var tname = t.get_current();

        if ( inModel(ModelName, tname, axTableType.GetType()) )
        {
            result.add(tname);
            continue;
        }

        var tExt = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTableExtensionNames(tname); // Why collection?
        var tExtEnum = tExt.GetEnumerator();
        while( tExtEnum.moveNext() )
        {
            var tExtName = tExtEnum.Get_Current();
            if ( inModel(ModelName, tExtName, axTableExtType.GetType()) )
            {
                result.add(tExtName);
                continue;
            }
        }
    }

    return result;
}
4

1 回答 1

1

X++:https ://gist.github.com/mazzy-ax/4d4d06ec2fddd885b67527623467aee8

class Tables
{
    public static void Main(Args _args)
    {
        str aosServiceBin = 'C:\AOSService\webroot\bin';
        str packageDir = 'C:\AOSService\PackagesLocalDirectory';

        //or
        var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory::GetApplicationEnvironment();
        packageDir = environment.get_Aos().get_PackageDirectory();

        // it's kind of magic
        var runtimeProviderConfiguration = New Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration(packageDir);
        var metadataProviderFactory =  New Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory();
        var provider = metadataProviderFactory.CreateRuntimeProvider(runtimeProviderConfiguration);

        // object names
        print provider.Tables.ListObjectsForModel('FleetManagement');
        print provider.Tables.ListObjectsForModel('FleetManagementExtension');
        print provider.TableExtensions.ListObjectsForModel('FleetManagement');
        print provider.TableExtensions.ListObjectsForModel('FleetManagementExtension');

        // single object by name
        var custTransMetaData = provider.Tables.Read('CustTrans');
    }

}

Powershell 脚本:https ://gist.github.com/mazzy-ax/292f2ce1a8e79c39d1fc753bfca9c529

$aosServiceBin = 'C:\AOSService\webroot\bin'
$packageDir = 'C:\AOSService\PackagesLocalDirectory'

# or 
add-type -path (Join-Path $aosServiceBin 'Microsoft.Dynamics.ApplicationPlatform.Environment.dll')
$environment = [Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory]::GetApplicationEnvironment()
$packageDir = $environment.get_Aos().get_PackageDirectory()

# it's kind of magic
add-type -path (Join-Path $aosServiceBin 'Microsoft.Dynamics.Ax.Metadata.Storage.dll')
$runtimeProviderConfiguration = New-Object Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration $packageDir
$metadataProviderFactory =  New-Object Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory
$provider = $metadataProviderFactory.CreateRuntimeProvider($runtimeProviderConfiguration)

# object names
$provider.Tables.ListObjectsForModel('FleetManagement').count
$provider.Tables.ListObjectsForModel('FleetManagementExtension').count
$provider.TableExtensions.ListObjectsForModel('FleetManagement').count
$provider.TableExtensions.ListObjectsForModel('FleetManagementExtension').count

# single object by name
$provider.Tables.Read('CustTrans')

C#、T-SQL可以自己创建镜像。

于 2017-08-16T11:43:10.983 回答