views:

337

answers:

1

I have a dbml file that was autogenerated. I want to, in code (VB.Net) get the Association values for one of the properties. How is this accomplished?

Basically, in my vb.Net code I'd like to somehow know (in the following example) the LookupDocumentStatus.IsForeignKey and the LookupDocumentStatus.ThisKey value.

Is there an easy way to get this value?

_ Public Property LookupDocumentStatus() As LookupDocumentStatus Get Return Me._LookupDocumentStatus.Entity End Get Set

A: 

Answered my own question from lots of research from http://blog.csdn.net/greatbag/archive/2009/02/12/3881235.aspx

In simplicity this is what I did (of course, more code to "do" what i need to, but, here it is in basic format)

 Dim infos As PropertyInfo() = MyObject.GetType().GetProperties()
 For Each pi As PropertyInfo In infos
      Dim isAssociation As Boolean = False
      For Each obj As Object In pi.GetCustomAttributes(True)
      If obj.[GetType]() Is GetType(System.Data.Linq.Mapping.AssociationAttribute) Then
         'Do some code here
      Exit For
      End If
  Next
sugarcrum