Forum:  Designer

Thread:  Foreach RelatedEntity - order?


gregsohl (User)   Posted on: 01-Aug-2018 17:41:52.
Hi,

LLBLGen: 2.6 Final

I have a question on the order of "<[Foreach RelatedEntity ManyToOne]>". I'm generating some code for the first time in a long, long time and comparing to the existing code to be sure we are still doing it right. Doing well, however the output order of the relations is coming out in different orders. When there are multiple relationships to one table, the output is created in the opposite order. While this doesn't matter functionally, it makes it pretty hard to determine if what I'm getting matches existing code.

Examples:

Existing Code:
Code:

    // CellDependency.DependantStatementDefinitionNumber - CellDefinition.StatementDefinitionNumber
    // CellDependency.DependantIdentifierDefinitionNumber - CellDefinition.IdentifierDefinitionNumber
    // CellDependency.DependantCellDefinitionNumber - CellDefinition.CellDefinitionNumber
    _cellDefinition = null;        
    // CellDependency.DependencyStatementDefinitionNumber - CellDefinition.StatementDefinitionNumber
    // CellDependency.DependencyIdentifierDefinitionNumber - CellDefinition.IdentifierDefinitionNumber
    // CellDependency.DependencyBeginningCellDefinitionNumber - CellDefinition.CellDefinitionNumber
    _cellDefinition_ = null;


Newly Generated Code:
Code:

    // CellDependency.DependencyStatementDefinitionNumber - CellDefinition.StatementDefinitionNumber
    // CellDependency.DependencyIdentifierDefinitionNumber - CellDefinition.IdentifierDefinitionNumber
    // CellDependency.DependencyBeginningCellDefinitionNumber - CellDefinition.CellDefinitionNumber
    _cellDefinition_ = null;
    // CellDependency.DependantStatementDefinitionNumber - CellDefinition.StatementDefinitionNumber
    // CellDependency.DependantIdentifierDefinitionNumber - CellDefinition.IdentifierDefinitionNumber
    // CellDependency.DependantCellDefinitionNumber - CellDefinition.CellDefinitionNumber
    _cellDefinition = null;


Many of the Foreach commands indicate that they sort the output. Foreach RelatedEntity does not.

How can I get consistent, and expected/sorted order on RelatedEntities?

Thanks.

Greg
Walaa (Support Team)   Posted on: 01-Aug-2018 21:28:31.
Did you make sure you are comparing (existing code) code generated using the same version/release of the Designer and using the same LLBLGen project file?

I'm afraid you are comparing old generated code, in this case there is a chance the LLBLGen project file has been changed.


gregsohl (User)   Posted on: 01-Aug-2018 21:39:34.
Thanks.

I cannot verify that for certain, although the existing code header says "LLBLGen Pro version: 1.0.2004.2" and I'm currently using v2.6 final.

However my questions are unaffected by that -
Why is it coming out in reverse alphabetical order?
How can I control the order?

Greg
Otis (LLBLGen Pro Team)   Posted on: 02-Aug-2018 19:05:19.
In v2.6 you can't control the order, the elements are handled in the order in which they're stored in the collection inside the entity (EntityDefinition.Relations), so the order in which they're deserialized is the one they're handled in.

Which is every time the same btw (2.6 was the last version which used the binary format so uses binary serialization), but there's no ordering applied so there's no guarantee the order is the same.

If you want an ordering there, you can alter the code generator sourcecode btw, it's in the SDK archive on the website: log into the site with your customerid+pwd and go to My Account -> Downloads -> 2.6 -> Extras. There you'll find the SDK which contains all sourcecode for e.g. runtime, code generators etc. Go to TDLInterpreter\Interpreter.cs, line 3101 and apply ordering there.

The code is over 10 years old so it might look a little ... old fashioned Regular Smiley


gregsohl (User)   Posted on: 02-Aug-2018 19:13:55.
Thanks Frans. I have enough files to compare that it may be worth my time to make that code change and recompile the generator. Think I have the right SDK downloaded already, but will need to unzip and see if I can compile.

Greg
Walaa (Support Team)   Posted on: 02-Aug-2018 19:26:56.
I'll close this thread for now.
If you still face issues with it, please post back here and the thread will be automatically re-open.


gregsohl (User)   Posted on: 02-Aug-2018 21:40:00.
Found it. "Fixed" it. I'll share here, not that anyone but me is still stuck on v2.6 Regular Smiley

It was being sorted, but by the EntityRelation.RelationEndName. For multiple relations to the same table, the RelationEndName is always the same. The adorned name, with stacks of underscores to make the names unique, is in EntityRelation.UtilizingPropertyName.

The sort is encapsulated in method SortRelationsToWalk. It is used for both:
  • CallByFKReference
  • Foreach RelatedEntity

Updated code is in project TDLInterpreter, file Interpreter.cs
Code:

/// <summary>
/// Sorts the relations to walk.
/// </summary>
/// <param name="relationsToWalk">The relations to walk.</param>
private void SortRelationsToWalk(List<EntityRelation> relationsToWalk)
{
    relationsToWalk.Sort(delegate(EntityRelation relation1, EntityRelation relation2) { return relation1.UtilizingPropertyName.CompareTo(relation2.UtilizingPropertyName); });
}


Thanks again.

Greg
Otis (LLBLGen Pro Team)   Posted on: 03-Aug-2018 08:50:44.
thanks for sharing! Regular Smiley