async Task InsertInner(Dictionary <string, string> insertCommands, IEntity record) { foreach (var type in TopToBottomHierarchy) { var tableName = type.TableName; var insertCommandfortable = insertCommands[type.TableName]; var insertValueResult = await Db.ExecuteScalar(insertCommandfortable, CommandType.Text, CreateParameters(type, record)).ConfigureAwait(false); var autoNumber = ObjectType.FindAutoNumber(); if (autoNumber != null) { if (Sql == SqlDialect.MSSQL) { var autoNumberType = Type.GetType(autoNumber.PropertyType); var insertValueResultConverted = ConvertTo(insertValueResult, autoNumberType); record.GetType().GetProperty(autoNumber.Name).SetValue(record, insertValueResultConverted); } else { record.GetType().GetProperty(autoNumber.Name).SetValue(record, Convert.ToInt32(insertValueResult)); } } } }