Pages

Thursday, September 14, 2017

Sample loop through metadata of model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Dynamics.AX.Metadata.Management;
using Microsoft.Dynamics.AX.Metadata.Modeling;
using Microsoft.Dynamics.AX.Metadata.Storage;
using Microsoft.Dynamics.AX.Metadata.Providers;
using Microsoft.Dynamics.AX.Metadata.MetaModel;

namespace MetaDataExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string packagesLocalDirectory = @"J:\AosService\PackagesLocalDirectory";
            IMetadataProvider diskMetadataProvider = new MetadataProviderFactory().CreateDiskProvider(packagesLocalDirectory);

            var l = diskMetadataProvider.Tables.ListObjects("MyModelName");
            var le = l.GetEnumerator();

            while (le.MoveNext())
            {
                AxTable t = diskMetadataProvider.Tables.Read(le.Current);
                Console.WriteLine(t.Name);
            }

            Console.ReadKey();
        }

    }
}

No comments: