Massive.DynamicModel.KeyValues C# (CSharp) Method

KeyValues() public method

This will return a string/object dictionary for dropdowns etc
public KeyValues ( string orderBy = "" ) : object>.IDictionary
orderBy string
return object>.IDictionary
        public virtual IDictionary<string, object> KeyValues(string orderBy = "")
        {
            if (String.IsNullOrEmpty(DescriptorField))
                throw new InvalidOperationException("There's no DescriptorField set - do this in your constructor to describe the text value you want to see");
            var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName);
            if (!String.IsNullOrEmpty(orderBy))
                sql += "ORDER BY " + orderBy;

            var results = Query(sql).ToList().Cast<IDictionary<string, object>>();
            return results.ToDictionary(key => key[PrimaryKeyField].ToString(), value => value[DescriptorField]);
        }