コード例 #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);
        }
コード例 #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());
 }
コード例 #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());
 }
コード例 #4
0
 /// <summary>
 /// Perform a model update operation asynchronously.
 /// </summary>
 private async Task PerformUpdateAsync()
 {
     await Query.Where(PrimaryKeyName.ToSnakeCase(), PrimaryKey).UpdateAsync(PrepareBindings());
 }
コード例 #5
0
 /// <summary>
 /// Perform a model update operation.
 /// </summary>
 private void PerformUpdate()
 {
     Query.Where(PrimaryKeyName.ToSnakeCase(), PrimaryKey).Update(PrepareBindings());
 }