Esempio n. 1
0
        /// <summary>
        /// Get the current query value bindings.
        /// </summary>
        /// <returns>A collection of columns and values.</returns>
        private Dictionary <string, dynamic> PrepareBindings()
        {
            PropertyInfo[] properties             = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            Dictionary <string, dynamic> bindings = properties.Where(p => p.PropertyType.IsValueType || p.PropertyType == typeof(string)).ToDictionary(p => Attribute.IsDefined(p, typeof(ColumnAttribute)) ? p.GetCustomAttribute <ColumnAttribute>().Name : p.Name.ToSnakeCase(), p => p.GetValue(this));

            bindings.Remove(PrimaryKeyName.ToSnakeCase());

            return(bindings);
        }
Esempio n. 2
0
 /// <summary>
 /// Asynchronously find a model by its primary key.
 /// </summary>
 /// <param name="id">The value of the primary key.</param>
 /// <returns>An instance of the hydrated model.</returns>
 public static async Task <T> FindAsync(int id)
 {
     return(await Query.Where(PrimaryKeyName.ToSnakeCase(), id).FirstAsync());
 }
Esempio n. 3
0
 /// <summary>
 /// Find a model by its primary key.
 /// </summary>
 /// <param name="id">The value of the primary key.</param>
 /// <returns>An instance of the hydrated model.</returns>
 public static T Find(int id)
 {
     return(Query.Where(PrimaryKeyName.ToSnakeCase(), id).First());
 }
Esempio n. 4
0
 /// <summary>
 /// Perform a model update operation asynchronously.
 /// </summary>
 private async Task PerformUpdateAsync()
 {
     await Query.Where(PrimaryKeyName.ToSnakeCase(), PrimaryKey).UpdateAsync(PrepareBindings());
 }
Esempio n. 5
0
 /// <summary>
 /// Perform a model update operation.
 /// </summary>
 private void PerformUpdate()
 {
     Query.Where(PrimaryKeyName.ToSnakeCase(), PrimaryKey).Update(PrepareBindings());
 }