A bug in the outer join attribute in formdatasource

Source: Internet
Author: User
After a day of being depressed, I finally solved a problem. Once again, I strongly despise the dynamics ax documentation. Many very strange usage documents are not introduced at all !!
Problem description:
To create an attribute for the combination of Itemid and inventdimid in the inventsum table without changing the structure of the table, a table named inventsumproperty is created. The field description is as follows:
Itemid: item ID
Inventdimid: warehouse dimension group ID
Property: New Property
Add a connection to the table inventsum. The connection fields are Itemid and inventdimid.
To display these attributes, a new form is created. Because you need to display the values of certain materials and inventory latitudes, inventsum needs to be inline with the inventdim table, and then external with inventsumproperty.
In this way, this form has three data sources.
Inventsum joinsource: NULL linktype: delayed
Inventdim joinsource: inventsum linktype: innerjoin
Inventsumproperty joinsource: inventsum linktype: outerjoin
Put some of the things you want to show in the grid. I thought everything was going to be good. Who thought it was really depressing? The following error was prompted when I opened the form:
You cannot select records in inventsumexternal (inventsumexternal. The join table in the WHERE clause does not contain any link.
This prompt is an inexplicable and does not contain any connections ?? I have added a connection to the table inventsumexternal... strange!
Troubleshooting Process
I have done many inline operations between three tables before, so I tried to change the linktype of inventsumproperty to innerjoin. As a result, no error is reported! But this still does not meet the requirements, because if it is changed to innerjoin, many inventsum tables exist, but the values without corresponding attributes in inventsumproperty will not be displayed, this does not meet the requirements.
I checked that an error occurred while executing the inventsum_ds excutequery method. I used SQL tracing without tracking any statements. It seems that an error occurred during the statement analysis phase and the SQL statement was not executed.
Reload the excutequery method of inventsum_ds and write it before super. Code : Info (inventsum_ds.query (). datasourceno ( 1 ). Tostring ());

The following SQL statement is obtained: Select   *   From Inventsum
Join   *   From Inventdim
Where Inventsum. inventdimid = Inventdim. inventdimid
Outer   Join   *   From Inventsumexternal
Where Inventsum. Itemid = Inventsumexternal. Itemid And Inventsum. inventdimid = Inventsumexternal. inventdimid

This statement should be submitted to SQL Server for analysis. Of course, this statement is only a semi-finished product and cannot be executed in SQL Server. It also has syntax errors in X ++.
The SQL version and X ++ version are modified as follows:
SQL version: Select   *   From Inventsum
Inner   Join Inventdim On Inventsum. inventdimid = Inventdim. inventdimid
Left   Join Inventsumexternal On Inventsum. inventdimid = Inventsumexternal. inventdimid

The preceding statement runs on SQL server without any problems.
X ++ version: Static   Void Sqltest (ARGs _ ARGs)
{
Inventsum;
Inventdim;
Inventsumexternal;
;

Select * From inventsum
Join * From inventdim
Where inventsum. inventdimid = Inventdim. inventdimid
Outer Join * From inventsumexternal
Where inventsum. Itemid = Inventsumexternal. Itemid &&
Inventsum. inventdimid = Inventsumexternal. inventdimid;

}

Run the preceding statement and report the same error as when using form !! It seems that the problem lies in this. The X ++ compiler has a bug when compiling this statement and cannot generate the correct SQL statement! I am so depressed that I have been stuck here for a long time. I tried it and suddenly thought of moving the sequence of outer join to the beginning of join. Static   Void Sqltest (ARGs _ ARGs)
{
Inventsum;
Inventdim;
Inventsumexternal;
;

Select * From inventsum
Outer Join * From inventsumexternal
Where inventsum. Itemid = Inventsumexternal. Itemid &&
Inventsum. inventdimid = Inventsumexternal. inventdimid
Join * From inventdim
Where inventsum. inventdimid = Inventdim. inventdimid;
 

}

ft! I did not expect this to happen! It's confusing!
if you can find a way to put the X ++ query code generated by the query corresponding to formdatasource in front of outerjoin, should the problem be solved after innerjoin? Try to move inventsumexternal_ds to the front of inventdim_ds, which has no function ......
the query should be constructed when the init method of each data source is called. The execution sequence of the init method was tested before. It seems that the execution sequence is not correct, this may be executed first or later, and it has no relationship with the order shown by datasource in form. I suddenly remembered the two forms created in the previous test and used the same two data sources. The results showed that the init method of the two data sources was called in the opposite order, is it related to the order in which datasource was just created ???
A new form is created, and the preceding three datasource are still used, except that they are created in the following order
inventsum, inventsumexternal, inventdim
the connection data source and connection method are still set as above.
nnd: OK !!
I cannot understand it completely ......
conclusion:
the X ++ interpreter has a bug. If two data sources are associated with the same data source through innerjoin and outerjoin, remember that when creating a data source, the data source with the connection relationship outerjoin must be created before the innerjoin data source.
that asked again? What if both data sources connect to the same data source through outerjoin?
if you are old, don't try ax. I'm afraid it won't be considered at all. Would you like to try it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.