예제 #1
0
        public static TableInfo FromPoco(Type t)
        {
            var tableInfo = new TableInfo();

            // Get the table name
            var a = t.GetCustomAttributes(typeof(TableNameAttribute), true);
            tableInfo.TableName = a.Length == 0 ? t.Name : (a[0] as TableNameAttribute).Value;

            // Get the primary key
            a = t.GetCustomAttributes(typeof(PrimaryKeyAttribute), true);
            tableInfo.PrimaryKey = a.Length == 0 ? "ID" : (a[0] as PrimaryKeyAttribute).Value;
            tableInfo.SequenceName = a.Length == 0 ? null : (a[0] as PrimaryKeyAttribute).SequenceName;
            tableInfo.AutoIncrement = a.Length == 0 ? true : (a[0] as PrimaryKeyAttribute).AutoIncrement;

            // Set autoincrement false if primary key has multiple columns
            tableInfo.AutoIncrement = tableInfo.AutoIncrement ? !tableInfo.PrimaryKey.Contains(',') : tableInfo.AutoIncrement;

            return tableInfo;
        }
예제 #2
0
 public virtual void GetTableInfo(Type t, TableInfo ti) { }
예제 #3
0
        public Task <int> DeleteAsync(object poco)
        {
            TableInfo tableInfo = this.PocoDataFactory.TableInfoForType(poco.GetType());

            return(this.DeleteAsync(tableInfo.TableName, tableInfo.PrimaryKey, poco));
        }
예제 #4
0
        /// <summary>
        /// Performs an SQL Insert
        /// </summary>
        /// <param name="poco">The POCO object that specifies the column values to be inserted</param>
        /// <returns>The auto allocated primary key of the new record, or null for non-auto-increment tables</returns>
        /// <remarks>The name of the table, it's primary key and whether it's an auto-allocated primary key are retrieved
        /// from the POCO's attributes</remarks>
        public Task <object> InsertAsync <T>(T poco)
        {
            TableInfo tableInfo = this.PocoDataFactory.TableInfoForType(poco.GetType());

            return(this.InsertAsync(tableInfo.TableName, tableInfo.PrimaryKey, tableInfo.AutoIncrement, poco));
        }
예제 #5
0
        public Task <int> UpdateAsync(object poco, object primaryKeyValue, IEnumerable <string> columns)
        {
            TableInfo tableInfo = this.PocoDataFactory.TableInfoForType(poco.GetType());

            return(this.UpdateAsync(tableInfo.TableName, tableInfo.PrimaryKey, poco, primaryKeyValue, columns));
        }