Maintain fieldorder in entity from database

Posts   
 
    
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 10-Feb-2011 19:41:23   

In the generated code, the entities have their fields in alfabetic order. Normally this doesn't matter in your application. However, in some situations you like to maintain the order of the fields in the table or view. For example when exporting data to Excel from an ASP.NET application you prefer to have the handcrafted order of fields. In this way you can use some generic code to fill a datatable without the hassle of having a list with fieldnames and a displayorder to determine the order of fields

Is this possible in LLblgen Pro ?. Do you need to set a project property of use some other way.

Get a collection:


 EntityCollection<ViewUsersExportEntity> usercollection = new EntityCollection<ViewUsersExportEntity>();
            using (DataAccessAdapter ds = new DataAccessAdapter())
            {

                IPrefetchPath2 prefetch2 = new PrefetchPath2((int)EntityType.ViewUsersExportEntity);
                RelationPredicateBucket filter2 = new RelationPredicateBucket();
                filter2.PredicateExpression.Add(ViewUsersExportFields.PortalId == currentPortal.PortalId);
                ds.FetchEntityCollection(usercollection, filter2, prefetch2);


            }

Fill the datatable

   DataTable dataTable = new DataTable();
            IEntityFields2 fields = usercollection.EntityFactoryToUse.CreateFields();

            for (int i = 0; i < fields.Count; i++)
            {
                dataTable.Columns.Add(fields[i].Name, Nullable.GetUnderlyingType(fields[i].DataType) ?? fields[i].DataType);
            }

            foreach (IEntity2 entity in collection)
            {
                DataRow row = dataTable.NewRow();
                for (int i = 0; i < fields.Count; i++)
                {
                    if (entity.Fields[i].CurrentValue != null) row[entity.Fields[i].Name] = entity.Fields[i].CurrentValue;
                }
                dataTable.Rows.Add(row);
            }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Feb-2011 20:30:20   

Field order based on the ordinal order is added to v3.1, which was released last monday simple_smile So if you're a v3 user, you can upgrade to v3.1 for free by downloading it from the customer area.

Frans Bouma | Lead developer LLBLGen Pro
dotprof
User
Posts: 20
Joined: 19-Feb-2010
# Posted on: 11-Feb-2011 06:06:45   

Thanks, I will do that. That's what you call "just in time delivery"simple_smile

Otis wrote:

Field order based on the ordinal order is added to v3.1, which was released last monday simple_smile So if you're a v3 user, you can upgrade to v3.1 for free by downloading it from the customer area.