Fields mapped on related fields field index

Posts   
 
    
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 19-Oct-2006 20:15:08   

Let's say I have an ApplicantCertification entity with a CertificationDescription field mapped as a field on related field from Certification.Description.

My problem is, CertificationDescription isn't in the ApplicantCertificationFieldIndex enumeration. Is there an enumeration somewhere with this item?

Alternatively, maybe someone could tell me how to get "CertificationDescription" as a string from an existing entity.. For example, would it be possible to create a function called GetPropertyNameString that satisfies the test below?


Dim appCert As New ApplicantCertification()
Assert.IsTrue(GetPropertyNameString(appCert.CertificationDescription) = "CertificationDescription")

Sorry for all the weird questions lately. It has a lot to do with making data binding in our app more type-safe..

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Oct-2006 02:54:36   

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3306&HighLight=1

Is this similar to your question? If you could provide more explanation as to why you need the index and the string it may be easier to give you the solution.

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 20-Oct-2006 15:46:25   

bclubb wrote:

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3306&HighLight=1

Is this similar to your question? If you could provide more explanation as to why you need the index and the string it may be easier to give you the solution.

We're using Infragistics grids in our app, binding an enititycollection directly do it. Every column in an Infragistics grid is accessible with a key, and since we don't know which columns will be displayed at runtime, we have toiterate over the coloumns to determine which are available. Here's some code..


        For Each ugc As UltraGridColumn In grdMain.DisplayLayout.Bands(0).Columns
            Select Case ugc.Key
                Case ApplicantCertificationInformationFieldIndex.CertificationCodeMasterId.ToString()
...

                Case "CertificationDescription"
......

Notice the key is the same as the property name in the entity. Well, if the fields on related fields property isn't in the FieldIndex, I end up having to hard code the values.

Hard coding = bad.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 20-Oct-2006 17:38:36   

You can determine which fields are visible as properties, by using the entitycollection's code to produce propertydescriptors. As you bind the entitycollection directly to the grid, I assume you're using 1.0.2005.1/.net 1.x. If you're using v2.0 (we can't keep track of that ourselves, please state this with your posts... ), you've to use an EntityView2, as ITypedList is implemented on that, but it works roughly the same. (you then call EntityView2.GetPropertyDescriptors(dummy, null); )

So typically you do:

EntityCollection dummyCol = new EntityCollection(new ApplicantCertificationEntityFactory());
IEntity2 dummy = new ApplicantCertificationEntity();
PropertyDescriptorCollection propertyDescriptors = dummyCol.GetPropertyDescriptors(dummy, typeof(ApplicantCertificationEntity));

If you don't want collection properties to be present, use the overload which accepts skipCollections (boolean), and pass in true.

this gives property descriptors for all properties which are visible in the entity, and which are useful, so properties which would be reported back to a grid if you bound dummyCol to it.

You can then walk the properties, and use the names for columns.

Frans Bouma | Lead developer LLBLGen Pro