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);
}