Reputation: 8764
I have a linq Context that I am looking at all the data Tables, I am trying to get the list of fields in all tables
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);
}
}
}
That does not deliver me the columns in each table.
Any thoughts?
simplistically I am trying to get all the properties when all i have is a propertyInfo of the object i am trying to get properties for.
-Hurricane
Upvotes: 0
Views: 366
Reputation: 103740
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);
}
}
}
Change it to that. You were reflecting over System.Data.Linq.Table, but remember, the property on the DataContext is Table<T> where T is the class that represents the actual table in the database. Therefore, you need to reflect over the T instead.
Upvotes: 1