Default Projection reverses fields

Posts   
 
    
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 10-Dec-2008 23:18:10   

Somewhere in this:


        Dim toReturn As New DataTable
        Dim propertyProjectors As List(Of IEntityPropertyProjector) = EntityFields2.ConvertToProjectors(entities.EntityFactoryToUse.CreateFields)
        entities.DefaultView.CreateProjection(propertyProjectors, toReturn, True, filter)

The order of fields gets reversed. Just a note. Easily fixed on my side with:


        propertyProjectors.Sort(New System.Comparison(Of IEntityPropertyProjector)(Function(x As IEntityPropertyProjector, y As IEntityPropertyProjector) (x.DefaultValueProducer.FieldIndex.CompareTo(y.DefaultValueProducer.FieldIndex))))

but just thought you'd like to know. simple_smile

Jeff...

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 11-Dec-2008 08:40:51   

Would you please explain in more details what do you mean by reversed?

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 21-Dec-2008 22:28:21   

The resulting datatable has the order of fields reversed so that the field with FieldIndex = 0 in the underlying table is shown last in the datatable.

Note: I think the same thing happens to the order of rows, so that if the entitycollection was sorted ascending, the resulting data comes out sorted descending.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 22-Dec-2008 11:02:28   

The order of the fields is indeed in reverse order due to the internal algorithm used (to avoid overloaded fields being ignored). Add propertyProjectors.Reverse() below the Dim statement to fix this. I'm on the fence if this is a thing we should release now as a fix, as it might cause problems in user programs... You as a user know that better than us as your software will likely run into problems if you keep the Reverse() statement yourself. Would you say you'd like this as a fix in the current v2.6 builds? I would think you would not want this in between versions, but I'm not sure.

The order of the rows... we'll look into that. (projection of collection. The projection of a datareader is obviously in the order the reader retrieves the rows)

(edit) The order in the rows of the projection of a collection, this is from a view on the collection to a DataTable? As that uses a normal foreach, so in the same order...

Frans Bouma | Lead developer LLBLGen Pro