2009-05-19 74 views
0

我有一个自动生成的dbml文件。我想在代码(VB.Net)中获取其中一个属性的关联值。这是如何完成的?LINQ to SQL并从dbml文件中获取关联值

基本上,我vb.Net代码,我想以某种方式知道(在下面的例子)LookupDocumentStatus.IsForeignKey和LookupDocumentStatus.ThisKey值。

有没有简单的方法来获得这个值?

_ 公共财产LookupDocumentStatus()作为LookupDocumentStatus 获取 返回Me._LookupDocumentStatus.Entity 最终获取 设置

回答

0

回答了大量的研究我自己的问题,从http://blog.csdn.net/greatbag/archive/2009/02/12/3881235.aspx

在简单,这是什么我做了(当然,更多的代码来“做”我所需要的,但是,这里是基本格式)

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