views:

144

answers:

1

So, when you bind a collection of Entity objects to a grid component, the grid displays those fields in the sequential order they are found in the SQL Table they came from. This shows that the ordinal position of the fields are associated with their corresponding entity properties... somehow or other.

So here is the question: How can I obtain the table field ordinal position by reflecting over an Entity Framework Entity's properties?

Let me tell you what I know and what I have tried. Apparently, each data field property in an EF Entity is decorated with a System.Runtime.Serialization.DataMemberAttribute. This attribute appears to have an Order property. However, I have discovered that this property does not contain what I am looking for. The value for all Data Properties in an Entity seems to be -1. What ever order is, it isn't ordinal position.

Has anybody dealt with this?

A: 

Relational data attributes have no order nor ordinal. Columns in a table have no order, nor ordinal (physical implementation asside). Result set column positions correspond to specific queries, based on the projected list of the query, and the application always knows the ordinal because it knows the projection list it asked for.

If you want to display columns in a certain order in a grid, display them in the order you desire. If you want to retrieve a column ordinal number in the physical storage for ad-hoc queries not known at development time, then you're going to interogate the physical storage directly using some storage specific mechanism. For example, if the storage is SQL Server you would look in sys.columns.

Remus Rusanu
That ("Columns in a table have no order, nor ordinal") is true in relational theory, false for nearly every SQL DB in existence. Most SQL DBs have a column order feature.
Craig Stuntz