0

I need to get column name and value from a table which I know only the name. I try lot of stuff but without success.

I use this for get my table :

var table = oSession.ctx.GetType()
                       .GetProperty("country")
                       .GetValue(oSession.ctx, null);

I'm lock with that I can't retrieve the informations of my columns .. Perhaps I have already try this :

List<string> columnsNames = table.GetType().GetFields().Select(field => field.Name).ToList();

Thx for your help..

Yvan
  • 1,081
  • 2
  • 20
  • 27

2 Answers2

2

Use ((IQueryable)table).ElementType.GetProperties() as a starting point. Also you can get some ideas from Dynamic LINQ query to get Field value from Database

Community
  • 1
  • 1
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343
0

you can probably try using GetProperties() table.GetType().GetProperties().Where(p => !(p.GetMethod.IsVirtual || p.GetIndexParameters().Length > 0)).ToList()

gamepop
  • 424
  • 2
  • 13