예제 #1
0
        /// <summary>
        /// Returns a string-string dictionary which can be directly bound to ASP.NET dropdowns etc. (see https://stackoverflow.com/a/805610/795690).
        /// </summary>
        /// <param name="orderBy">Order by, defaults to primary key</param>
        /// <returns></returns>
        override public IDictionary <string, string> KeyValues(string orderBy = null)
        {
            if (IsGeneric)
            {
                // TO DO: Make sure this works even when there is mapping
                var db = new MightyOrm(null, TableName, PrimaryKeyInfo.PrimaryKeyColumn, ValueColumn, connectionProvider: new PresetsConnectionProvider(ConnectionString, Factory, Plugin.GetType()));
                return(db.KeyValues(orderBy));
            }
            string partialMessage = $" to call {nameof(KeyValues)}, please provide one in your constructor";
            string valueColumn    = CheckGetValueColumn(partialMessage);
            string pkColumn       = PrimaryKeyInfo.CheckGetKeyColumn(partialMessage);
            // this cast here casts the IEnumerable of ExpandoObject's to an IEnumerable of string-object dictionaries
            // (since each ExpandoObject can be cast like that)
            var results = All(orderBy: orderBy ?? pkColumn, columns: $"{pkColumn}, {valueColumn}").Cast <IDictionary <string, object> >();

            return(results.ToDictionary(item => item[pkColumn].ToString(), item => item[valueColumn].ToString()));
        }
예제 #2
0
        /// <summary>
        /// Returns a string-string dictionary which can be directly bound to ASP.NET dropdowns etc. (see https://stackoverflow.com/a/805610/795690).
        /// </summary>
        /// <param name="orderBy">Order by, defaults to primary key</param>
        /// <param name="cancellationToken">Async <see cref="CancellationToken"/></param>
        /// <returns></returns>
        override public async Task <IDictionary <string, string> > KeyValuesAsync(CancellationToken cancellationToken, string orderBy = "")
        {
            if (IsGeneric)
            {
                // TO DO: Make sure this works even when there is mapping
                var db = new MightyOrm(null, TableName, PrimaryKeyInfo.PrimaryKeyColumn, ValueColumn, connectionProvider: new PresetsConnectionProvider(ConnectionString, Factory, Plugin.GetType()));
                return(await db.KeyValuesAsync(cancellationToken, orderBy));
            }
            string partialMessage = $" to call {nameof(KeyValuesAsync)}, please provide one in your constructor";
            string valueColumn    = CheckGetValueColumn(partialMessage);
            string pkColumn       = PrimaryKeyInfo.CheckGetKeyColumn(partialMessage);
            var    results        = await AllAsync(cancellationToken, orderBy : orderBy ?? pkColumn, columns : $"{pkColumn}, {valueColumn}");

            // Convert results to required format
            var retval = new Dictionary <string, string>();
            await results.ForEachAsync(result => {
                var expando = result as ExpandoObject;
                var item    = expando.ToDictionary();
                retval.Add(item[pkColumn].ToString(), item[valueColumn].ToString());
            });

            return(retval);
        }
예제 #3
0
 /// <summary>
 /// Wrap MightyOrm to provide Massive-compatible dynamic methods.
 /// You can access almost all this functionality non-dynamically (and if you do, you get IntelliSense, which makes life easier).
 /// </summary>
 /// <param name="me">The <see cref="MightyOrm{T}"/> instance</param>
 internal DynamicMethodProvider(MightyOrm <T> me)
 {
     Mighty = me;
 }