How to use Group By in a D365FO data entity - axapta

I'm creating a data entity with multiple tables and I'm getting duplicate results. Because of the nature of the duplicates, I thought an easy solution would be to add the relevant fields to the Group By section in the primary datasource. However, when I run the entity as a data project in the DMF, I'm getting the following error:
Has anybody run into this before and how do I resolve it? I've tried adding the RecId to the group by (even though it shouldn't even be in the select list as it is not in the field list for the entity). I have noticed that adding fields to the Group By section changes the view in SQL and removes all of the RecId#2, Partitian#2 etc. fields. Does the Group By section even work or is it a broken "feature"?
The entity works perfectly (other than with duplicate results of course) when I remove all fields from the group by section.
UPDATE: From what I can find online, the group by functionality doesn't work. I'll update this question if somebody finds an answer. I am lucky this was an XML export, so I was able to use a XSLT file in the transformations under data entity mapping to remove duplicates.

Related

Symfony CollectionType update Entities

I can't believe this hasn't come up for other people, but I'm unable to find a solution.
Let's say I have two entity types, A and B with a one-to-many relationship. A has a collection of Bs.
The form for A has a CollectionType for the Bs, with a custom entry_type for B, allow_add and allow_delete set to true. When the form is created/populated/rendered, the Bs' fields are identified by their index in the collection. When the form is posted back, the fields are mapped back onto the B entities according to the index again.
What if the database in the mean time decided to return the Bs in a different order? Then the values get swapped around on the Bs! I can't have that, as other entities will reference the Bs and now they've changed their meaning!
Even if the database doesn't change the order, the same issue appears when a B is deleted: The fields get shifted through the Bs and a different one deleted! (Ok, I'm not a 100% certain this happens, as there's a gap then in the numbering of the posted fields.) I've found this similar question where it does happen when another one is created (Symfony CollectionType regards deletion+creation as a modification of an item), but that sort of drifted from the issue and there's no usable answer.
How do I make sure the form is updating the entities the user actually edited?
I already tried to render the Bs' IDs as a HiddenType, but then the form rightfully complains that the ID has no setter. It would probably force an ID on the wrong B anyways and Doctrine doesn't like that. I suppose I could add the Bs as unmapped and copy the values over to the correct objects manually, but that would defeat a good chunk of Symfony's form system.
I've used CollectionType before, but not for entities that are referenced elsewhere. I would then delete all of the previous entities and create the collection anew from the posted data. But I can't do that now, can I?
Since doctrine 2.1, it's possible to change how associations are indexed. This will allow you to use the id as the collection key (as the field has to be unique):
#OneToMany(targetEntity="B", mappedBy="A", indexBy="id")
You might also need to enable orphanRemoval so that the data is actually removed instead of the relation just set to null.

A few questions regarding importing a manually created data entity

I used the data entity creation wizard and selected Reqplan table as the main data source, then I manually added ReqPlanVersion, ReqPO, ReqTrans table as additional data sources and created the relationships below.
As for the data entities fields I manually dragged a subsets of fields from the three manually added tables.
However when I try to import the data and add file, I receive the following issue:
Q1. In the past for some other entities I have changed ‘Allow Edit on Create’ from ‘Auto’ to ‘YES’ on these fields and it has worked but I am not sure if it’s the only way or is it following best practice? Also what is the determining factor for a field to be editable or not during import since they are all on AUTO?
When I try to map source to staging manually by drawing the mapping lines I get below issue:
Q2. What is going on with the configuration key? Is it because I manually dragged the fields from the additional data sources but not using the data entity creation wizard?
Lastly I been getting below issue:
Q3: Is there a way to find out which unique key it is referring to? Is it talking about the EntityKey in my Data Entity or Indexes in staging table? In either case there are more than one so I am not sure what it is referring to?
Thanks in advance.
Response from the community forum:
1) Check allowEdit property on table itself, so if it is "No" there then auto means "No". If you want to update them through data entity you will have to force them to "Yes"
2) It's not connected to manual addition, it just says that tables used in the entity has configuration key disabled, so you cannot export or import data into them, however, these tables could be added by wizard or manually, it does not matter. Also, Configuration key could be on fields as well or on EDT that these fields use, check them as well.
3) Entity has Key node and there and there you have key generated by wizard for you. It is used by framework to understand if record should be updated or created, if it does not work for you, change it on the data entity and regenerate staging. You need to refresh staging because error you get is SQL error, at this stage SSIS transfers data from a file into a staging table and data could not be copied because of index vialotion, so check staging table index and see if your file has any duplicates.

how to merge entity reference relationship field value

I am facing problem in drupal views.
In my view display table having relationship with other entity type.
I am not getting desire output. It show duplicate rows with same title due to entity relationship.
I wanted to aggregate entity relationship field with ",".
I already try some module like : view distinct, views_merge_rows.
But did not work for me.
Please suggest some module.
Have a look at Views Calc and if you cant do it in the database Views Aggregator Plus gives you even more options.

Why Updating From Database Does Not Bring All Tables from the Database?

When I update the model from database, I am not able to access to some of the tables as entity.
Through Model Browser, I can see those tables under MyDBEntities.Store (I don't know what it is) but under the Entity Types, these tables are not listed. Tried to downgrade to EF5, tried opening and updating the model with VS2012. Tried deleting and recreating the model so many times but no luck. If I right click on Entity Folder and select Add New Entity, under the Base Types, these tables are not listed either. All tables have PK and FK by the way. Anyone has a clue?
EDIT:
I just noticed, if remove the model and while updating it from database, if only add these 5 tables, they are being added properly. But this time caused the run-time error: Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
When you add an association table that creates M:N relation between two other tables and has no additional attributes, then the association table is not shown in the model.
See http://smehrozalam.wordpress.com/2010/06/29/entity-framework-queries-involving-many-to-many-relationship-tables/.

Symfony2: loading user roles from database

I'm running into a problem with the Symfony2 Security system, particularly when trying to load Roles from a database. Before going further, I am aware of FOSUserBundle, but at the moment, in an effort to better understand the Symfony2 framework, I want to try and make my bundle work using Symfony2 components only. TL;DR -> please don't tell me to just use the FOSUserBundle. :-)
I have 3 entities configured in my bundle, Accounts, AccountsRoles, and AccountsRepository.
src\RedK\Core\IndexBundle\Entity\Accounts.php
http://pastebin.com/0VgXvtJp
src\RedK\Core\IndexBundle\Entity\AccountsRoles.php
http://pastebin.com/GiKNnYg3
src\RedK\Core\IndexBundle\Entity\AccountsRepository.php
http://pastebin.com/SVuMVdpN
MySQL demo_template.accounts Table
http://pastebin.com/YzmjD9e4
MySQL demo_template.accounts_roles Table
http://pastebin.com/Ybwr4f7y
All aspects of the bundle were working correctly (registration, confirmation, password reset, and login) before I attempted to add the loading of user roles from a database. When I simply set the role to array('ROLE_USER') via the getRoles() { return array('ROLE_USER') }, authentication worked and the user successfully logged into the site.
However, upon attempting to integrate roles from the database, I receive the following error, which I understand is an instance of AuthenticationException:
Notice: Undefined index: id in /home/humplebert/Websites/www/template/vendor/doctrine/lib/Doctrine/ORM/Query/SqlWalker.php line 804
Stack Trace
http://pastebin.com/Sr5RvZaY
The exception is only generated when I modify the query in AccountsRepository and remove
the "->select()" and "->leftJoin()" components. In looking at the Stack Trace, around line 16 on the pastebin.com link, it appears I have all sorts of "crazy" happening with regards to the many-to-many mapping in the BasicEntityPersister.
I've searched high and low in my Entity classes for any reference to plain "id" and can find none. I've noticed that if I change the names of my "ID" columns in my entities to just "id" (i.e. replace "AccountsID" with "id" in src\RedK\Core\IndexBundle\Entity\Accounts) the error goes away (and is replaced with another error, more on that in a moment).
Question 1)
Is there something blatently wrong with my Entities to be generating the "Undefined index: id" error I am receiving? If not, does Symfony2/Doctrine2 require that Auto-Increment columns in be labeled "id"?
As I have continued to tinker, I decided to try renaming my table ID columns to "id". Therefore, src\RedK\Core\IndexBundle\Accounts replaces AccountsID with just "id". And likewise, src\RedK\Core\IndexBundle\AccountsRoles replaces RolesID with just "id". Upon doing so, the "Undefined index: id" error goes away. However, I am presented with a new error: "table or view demo_template.accounts_accountsroles does not exist". Well of course it doesn't exist, I don't have a table defined as accounts_accountsroles. I have two tables, accounts and accounts_roles.
Question 2)
In order to use the Symfony2/Doctrine2 tools for importing user roles from a database, what rules are there regarding the naming of the tables? Based on the error I received, it seems that some form of concatenation is taking place. Or have I just simply screwed up my annotations somewhere along the line?
Any help would be greatly appreciated.
Regarding Question 1) the short answer is no! For the long answer see section 5.3 Mapping Defaults in the Doctrine Association Mapping documentation:
It states that if you use this short annotation:
/** #ManyToMany(targetEntity="Group") */
private $groups;
"In that case, the name of the join table defaults to a combination of the simple, unqualified class names of the participating classes, separated by an underscore character. The names of the join columns default to the simple, unqualified class name of the targeted class followed by “_id”. The referencedColumnName always defaults to “id”, just as in one-to-one or many-to-one mappings."
You can override the defaults by providing more detailed many to many annotations (see link above) and therefore avoid the id error.
Regarding Question 2) the concatenation is correct. Many to many relationships require a third 'junction' table. The Doctrine paragraph above explains how the name of this table is generated.
I don't know why the 'table ... does not exist' error is occurring for the junction table as the annotations look ok to me. It appears as though your database schema is somehow out of sync with your annotations.
I implemented a solution, above FOSUserBundle and described it here
After implementing Role access throug Doctrine you still need to make a RoleHierarchy service aware of it.

Resources