public PocoData ForObject(object o, string primaryKeyName) { var t = o.GetType(); #if !POCO_NO_DYNAMIC if (t == typeof(System.Dynamic.ExpandoObject) || t == typeof(PocoExpando)) { var pd = new PocoData(); pd.TableInfo = new TableInfo(); pd.Columns = new Dictionary<string, PocoColumn>(StringComparer.OrdinalIgnoreCase); pd.Columns.Add(primaryKeyName, new ExpandoColumn() {ColumnName = primaryKeyName}); pd.TableInfo.PrimaryKey = primaryKeyName; pd.TableInfo.AutoIncrement = true; foreach (var col in ((IDictionary<string, object>) o).Keys) { if (col != primaryKeyName) pd.Columns.Add(col, new ExpandoColumn() {ColumnName = col}); } return pd; } else #endif return ForType(t); }
/// <summary> /// Performs an SQL Insert /// </summary> /// <param name="tableName">The name of the table to insert into</param> /// <param name="primaryKeyName">The name of the primary key column of the table</param> /// <param name="autoIncrement">True if the primary key is automatically allocated by the DB</param> /// <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>Inserts a poco into a table. If the poco has a property with the same name /// as the primary key the id of the new record is assigned to it. Either way, /// the new id is returned.</remarks> public virtual Task <object> InsertAsync <T>(string tableName, string primaryKeyName, bool autoIncrement, T poco) { PocoData pd = this.PocoDataFactory.ForObject(poco, primaryKeyName, autoIncrement); return(this.InsertAsyncImp(pd, tableName, primaryKeyName, autoIncrement, poco)); }
public MappingFactory(PocoData pocoData) { _pocoData = pocoData; }
public MappingFactory(PocoData pocoData, DbDataReader dataReader) { this._pocoData = pocoData; this._rowMapper = RowMappers.Select(mapper => mapper()).First(x => x.ShouldMap(pocoData)); this._rowMapper.Init(dataReader, pocoData); }