AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 07.05.2021, 10:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: Entity metadata in a console application
Источник: http://dev.goshoom.net/2021/05/entit...e-application/
==============

There was a question in the Community forum about creating tables in an external databases that would match the schema of F&O data entities.

One of the possible approaches is generating SQL code for CREATE TABLE statement. The information about field names, types and such things would be taken from F&O metadata and we already have a nice API for this purpose.

Here is code for simple console application getting some of the necessary data:

using System;using System.Collections.Generic;using System.Linq;using Microsoft.Dynamics.AX.Metadata.MetaModel;using Microsoft.Dynamics.AX.Metadata.Storage;using Microsoft.Dynamics.AX.Metadata.Storage.Runtime; namespace DataEntityFields{ public class Demo { public static void Main(string[] args) { var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory.GetApplicationEnvironment(); var runtimeConfiguration = new RuntimeProviderConfiguration(environment.Aos.PackageDirectory); var metadataProvider = new MetadataProviderFactory().CreateRuntimeProviderWithExtensions(runtimeConfiguration); AxDataEntityView entity = metadataProvider.DataEntityViews.Read("VendVendorV2Entity"); foreach (AxDataEntityViewMappedField entityField in entity.Fields.Where(f => f is AxDataEntityViewMappedField)) { var datasource = FindDataSource(entity.ViewMetadata.DataSources, entityField.DataSource); if (datasource == null) { continue; } AxTable table = metadataProvider.Tables.Read(datasource.Table); AxTableField field = table.Fields[entityField.DataField]; AxTableFieldString stringField = field as AxTableFieldString; if (stringField != null) { Console.WriteLine($"{entityField.Name} (String {stringField.StringSize})"); } } Console.ReadLine(); } private static AxQuerySimpleDataSource FindDataSource(IEnumerable dataSources, string dataSourceName) { foreach (AxQuerySimpleDataSource ds in dataSources) { if (ds.Name == dataSourceName) { return ds; } return FindDataSource(ds.DataSources, dataSourceName); } return null; } }}






Note that it requires references to a few assemblies:
  • Microsoft.Dynamics.AX.Metadata.dll
  • Microsoft.Dynamics.AX.Metadata.Core.dll
  • Microsoft.Dynamics.AX.Metadata.Storage.dll
  • Microsoft.Dynamics.ApplicationPlatform.Environment.dll



Источник: http://dev.goshoom.net/2021/05/entit...e-application/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamicsaxinsight: AX7/D365/Operations: Create customer postal address through data entity from .NET console application Blog bot DAX Blogs 0 20.09.2017 15:11
german_nav_developer: Dynamics NAV 2013 R2 multi-tenancy – Viele Mieterinnen ohne Stress und Neid Blog bot Dynamics CRM: Blogs 0 30.12.2013 19:00
german_nav_developer: Buildnummern-Übersicht Microsoft Dynamics NAV 2009 SP1 Blog bot Dynamics CRM: Blogs 0 11.06.2010 16:33
german_nav_developer: Buildnummern-Übersicht Microsoft Dynamics 5.0 Service Pack 1 Blog bot Dynamics CRM: Blogs 0 04.06.2010 12:51
Права на добавление объектов в Дизайнере Cyr NAV: Администрирование 10 13.06.2009 21:27
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра
Комбинированный вид Комбинированный вид

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 18:26.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.