0

I want to return some values using sqlite database with the following code:

    public Dictionary<string, string> GetRegistry()
    {
        var table = this.connection.Table<Registry>();
        Dictionary<string, string> RegistryItems = new Dictionary<string, string>();

        foreach (var item in table)
        {

        }
    }

Given that var item represents an sql table item, so saying item.Age will be an age and so on. I want to be able to return a dictionary where i can do something like this:

Dictionary registry = this.GetRegistry();
int myAge = registry["Age"];

What should I do within the foreach clause to make this happen? Thanks in advance!

miko
  • 61
  • 7
  • If you're using C# 6 I think you can do `nameof(item.Age)` to get "Age" back. But something tells me the column name should already be in your object... – Arian Motamedi Apr 26 '17 at 22:24
  • you want to iterate through each column of the table? – Jason Apr 26 '17 at 22:24
  • yes i cant do nameof(item.Age) because its a loop, the name of the column is dynamic – miko Apr 26 '17 at 22:26
  • in php i can do `foreach ($array as $key => $value) {}` and `$key` represents the name of the column – miko Apr 26 '17 at 22:37

1 Answers1

0

Given that table means sql table you could do something like:

public Dictionary<string, string> GetRegistry()
        {


            var table = this.connection.Table<Registry>();
            Dictionary<string, string> RegistryItems = new Dictionary<string, string>();

            var ages = table.Select(X => x.Name == "Age").ToList();

        }
Simsons
  • 12,295
  • 42
  • 153
  • 269