2009-06-12 57 views
0

我有我在看所有的數據表LINQ的背景下,我試圖讓所有表中的字段列表的PropertyInfo子屬性

 foreach (var code in ctx.GetType().GetProperties()) 
     { 
      Console.WriteLine(code.PropertyType + " - " + code.Name + " "); 
      if (code.PropertyType.ToString().Contains("System.Data.Linq.Table")) 
      { 
        //this does not give me what i want here 
        foreach (var pi in code.PropertyType.GetType().GetProperties()) 
        { 
        Console.WriteLine(pi.Name); 
        } 
      } 
     } 

這並不救我列在每個表。

有什麼想法?

simplistically我想獲得所有的屬性,當我所有的是我試圖獲取屬性的對象的propertyInfo。

-Hurricane

回答

1
foreach (var code in ctx.GetType().GetProperties()) 
     { 
      Console.WriteLine(code.PropertyType + " - " + code.Name + " "); 
      if (code.PropertyType.ToString().Contains("System.Data.Linq.Table")) 
      { 
        //this does not give me what i want here 
        foreach (var pi in code.PropertyType.GetGenericArguments()[0].GetProperties()) 
        { 
        Console.WriteLine(pi.Name); 
        } 
      } 
     } 

其更改爲。您反映了System.Data.Linq.Table,但請記住,DataContext上的屬性是表<T>其中T是表示數據庫中實際表的類。因此,您需要反思T。