web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to create a Data Entity based on a Query or a View in AX 7?

(0) ShareShare
ReportReport
Posted on by 792

Hello all,

I have a Query (based on a View) which I need to execute from outside AX through OData, so I need to create a Data Entity for that purpose. Now can I create a Data Entity in AX7 which will have a Query or a View in its Data Source?

I will give you an example.

I want to create a query which will have DirPartyTable (table) and DirPartyNamePrimaryAddressView (view) as datasources. Now this query needs to be called from outside AX7 through OData service, so I need to create a Data Entity for it. But now when I am creating this Data Entity, I can select DirPartyTable as primary datasource, but I cannot select the aforesaid View in this data entity.

How to go about it? Is this even possible?

If not, then how to create a Data Entity based on an existing Query?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Although you can't use the wizard to base your entity on a view, you can do it in the designer. I've just tried it and got the data entity successfully synchronized with database.

    Of course, you won't be able to write data through such an entity, unless you write custom code to put data to underlying tables.

  • Sagnik Majumder Profile Picture
    792 on at

    Hi Martin,

    Thanks for your help. I can now create the Data Entity successfully using all the Tables and Views I want as its underlying datasources from the Designer window.

    But I have one question, I am not sure how much its related to DAX though, but still if in case you can help.

    We are delivering a Client application to our customer by which he can make Odata calls to the Dynamics AX and fetch query result. Now if the customer makes some changes in his Data Entities in the AX end, he needs to update the OData Client Code as well. For that reason he needs to update the ODataClient.tt file included in our client application. This can be done by running the TextTransform.exe tool properly on the ODataClient.tt file in the client application. But in order to use this tt file, he needs to build the client application once. How can this be possible? Customer cannot have VS, and moreover we wont be delivering the entire VS project to him. So how can one use the updated .tt file with an application exe without building the project?

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    It would help if you told us something about your client application. I assume you have a solution using a T4 template (.tt) to generate some client code based on OData service metadata - maybe OData v4 Client Code Generator. Is it so?

    Also, what changes does the client make to the data entity if he doesn't have any development environment (Visual Studio)?

  • Sagnik Majumder Profile Picture
    792 on at

    The customer needs to fetch few query results from Dynamics AX into an external application, which for example say, a Console app. We will deliver two Visual Studio projects.

    1. Dynamics AX Project: it contains all the data entities and backend infrastructure in DAX end.

    2. External Console App: it contains all the calls to the various OData endpoints exposed by our data entities from the earlier project.

    Now in this Console app, we have included the OData v4 Client Code Generator and added the ODataClient.tt file (Set the MetadataDocumentUri to the OData url available from DAX). Its properties are:-

    Custom Tool: TextTemplatingFileGenerator

    Build Action: Compile

    CopyToLocal: True

    When compiled, it produces ODataClient.cs file and its included in the project.

    Now my expectation is customer will import the Dynamics AX Project into his AX environment, and he will use the Console App EXE to call the OData services. The Console App is an external application, so we wont deliver the whole project, we will be delivering just the Exe and the corresponding tt file.

    Now we must provide support for custom queries created by the customer as well. It wasn't a problem in AX 2012 because MetadataService & QueryService will do that smoothly. But here in AX7, customer will create new Data Entities. Then he needs to update the Odata v4 client code definitions as well. At run time, he can run TextTransform.exe tool and can update the ODataClient.cs file.

    Now I have noticed that even though I update the ODataClient.cs file using the tool, still you cannot use this updated file without building the entire Console app. Only when you build the console app, it uses the latest version of the client code file. But how the customer can build the Console App? We shouldn't be delivering the entire project to them. No one does, I think.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Again, how will the customer create new data entities if you say that they don't have Visual Studio? It seems to me that either don't have VS and therefore can't make changes, or they have VS and your argument that they can't build the solution because they don't have VS is invalid. (Let's discuss shipping of code vs. binaries later.)

    If you want to use a code generator and things may change, obviously it's necessary to re-generate and compile code. That's the whole point of code generators. So either you do it, or you have to use a solution that doesn't depend on any code generator.

  • Sagnik Majumder Profile Picture
    792 on at

    What you said is correct. But we assume Customer company's Administrator will have the Visual Studio installed in the Dynamics AX end so that they can create Data Entities, Queries or classes as & when required. But a Normal employee (or clerk) who is the end-user should not be using VisualStudio. They will simply use our .NET application to make calls to the AX and fetch query result or post invoices.

    But if OData Code Generator requires recompiling the entire solution, then we need to ship them the entire solution (with code) so that they can build it after changing some things in AX end. We can set permission to only Administrator to do these.

    I have also tried compiling the generated ODataClient.cs file using CSharpCodeProvider from the code at runtime and wanted to use the generated assembly to create instances using Reflection. But I failed as it couldn't compile the .cs file (file size more than 35 MB) stating “No logical space left to create more user strings”. So I left that approach.

    As per your last statement, is there any way to not depend on any code generators? Is it possible?

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    All right, so the argument that they can't recompile it because they don't have Visual Studio isn't valid. They do have a developer who will make changes in Visual Studio, so he could easily build not only the data entity, but also the client library.

    So the real reason is that you don't want to give them the code. But why? What do you have to hide in auto-generated code? Maybe it means that you mix it with your other code, but that's your own architecture. If it doesn't suit your needs, use a different architecture and split the generated code and your own code to two separate assemblies. You can give it to them as normal VS solution; no need for playing with code generation and compilation at runtime.

  • Community Member Profile Picture
    on at

    Hi Martin,

    How can I create  data entity without the wizard since I cannot find views as primary data source

  • Suggested answer
    SagnikMajumder Profile Picture
    10 on at

    You can select any random table (say X) as a primary data source and finish off the Data Entity creation process through the wizard. Then you open the newly created data entity in the Designer. There you can select the required View as your primary data source and also delete that table X. Save it and its done.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans