当前位置: 首页>>代码示例>>C#>>正文


C# AdoAdapter.GetSchema方法代码示例

本文整理汇总了C#中Simple.Data.Ado.AdoAdapter.GetSchema方法的典型用法代码示例。如果您正苦于以下问题:C# AdoAdapter.GetSchema方法的具体用法?C# AdoAdapter.GetSchema怎么用?C# AdoAdapter.GetSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Simple.Data.Ado.AdoAdapter的用法示例。


在下文中一共展示了AdoAdapter.GetSchema方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        public int Update(AdoAdapter adapter, string tableName, IList<IDictionary<string, object>> data, IDbTransaction transaction, IList<string> keyFields)
        {
            int count = 0;
            if (data == null) throw new ArgumentNullException("data");
            if (data.Count < 2) throw new ArgumentException("UpdateMany requires more than one record.");

            if (keyFields.Count == 0) throw new NotSupportedException("Adapter does not support key-based update for this object.");
            if (!AllRowsHaveSameKeys(data)) throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary<string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                    ExpressionHelper.CriteriaDictionaryToExpression(
                                                                        tableName, GetCriteria(keyFields, exampleRow)));

            using (var connectionScope = ConnectionScope.Create(transaction, adapter.CreateConnection))
            using (var command = commandBuilder.GetRepeatableCommand(connectionScope.Connection))
            {
                var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                foreach (var row in data)
                {
                    foreach (var kvp in row)
                    {
                        propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                    }
                    count += command.ExecuteNonQuery();
                }
            }

            return count;
        }
开发者ID:darrencauthon,项目名称:Simple.Data,代码行数:33,代码来源:BulkUpdater.cs

示例2: Insert

        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null,
                                  bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var dataDictionary = BuildDataDictionary(adapter, data, table);

            string columnList = dataDictionary.Keys.Select(c => c.QuotedName).Aggregate((agg, next) => agg + "," + next);
            string valueList = dataDictionary.Keys.Select(s => "?").Aggregate((agg, next) => agg + "," + next);

            var insertSql = new StringBuilder();
            insertSql.AppendFormat("INSERT INTO {0} ({1}) VALUES ({2});", table.QualifiedName, columnList, valueList);
            if (resultRequired)
            {
                var identityColumn = table.Columns.FirstOrDefault(c => c.IsIdentity);
                if (identityColumn != null)
                {
                    insertSql.AppendFormat(" SELECT * FROM {0} WHERE {1} = LAST_INSERT_ID();", table.QualifiedName,
                                           identityColumn.QuotedName);
                    return ExecuteSingletonQuery(adapter, insertSql.ToString(), dataDictionary.Keys,
                                                 dataDictionary.Values, transaction);
                }
            }
            Execute(adapter, insertSql.ToString(), dataDictionary.Keys, dataDictionary.Values, transaction);
            return null;
        }
开发者ID:andy01pr,项目名称:Simple.Data.Mysql,代码行数:25,代码来源:MysqlCustomInserter.cs

示例3: Insert

        public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction, Func<IDictionary<string,object>, Exception, bool> onError, bool resultRequired)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var columns = table.Columns.Where(c => !c.IsIdentity).ToList();

            string columnList = string.Join(",", columns.Select(c => c.QuotedName));
            string valueList = string.Join(",", columns.Select(c => "?"));

            string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";

            var helper = transaction == null
                             ? new BulkInserterHelper(adapter, data, table, columns)
                             : new BulkInserterTransactionHelper(adapter, data, table, columns, transaction);

            if (resultRequired)
            {
                var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);
                if (identityColumn != null)
                {
                    var identityFunction = adapter.GetIdentityFunction();
                    if (!string.IsNullOrWhiteSpace(identityFunction))
                    {
                        return InsertRowsAndReturn(adapter, identityFunction, helper, insertSql, table, onError);
                    }
                }
            }

            helper.InsertRowsWithoutFetchBack(insertSql, onError);

            return null;
        }
开发者ID:rposbo,项目名称:Simple.Data,代码行数:31,代码来源:BulkInserter.cs

示例4: Insert

        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null, bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var dataDictionary = BuildDataDictionary(adapter, data, table);

            string columnList = dataDictionary.Keys.Select(c => c.QuotedName).Aggregate((agg, next) => agg + "," + next);
            string valueList = dataDictionary.Keys.Select(s => "?").Aggregate((agg, next) => agg + "," + next);

            var insertSql = new StringBuilder();
            bool identityInsert = adapter.AdoOptions != null && adapter.AdoOptions.IdentityInsert;
            if (identityInsert)
            {
                insertSql.AppendFormat("SET IDENTITY_INSERT {0} ON; ", table.QualifiedName);
            }
            insertSql.AppendFormat("INSERT INTO {0} ({1})", table.QualifiedName, columnList);
            if (resultRequired)
            {
                insertSql.Append(" OUTPUT INSERTED.*");
            }
            insertSql.AppendFormat(" VALUES ({0})", valueList);
            
            if (identityInsert)
            {
                insertSql.AppendFormat("; SET IDENTITY_INSERT {0} OFF; ", table.QualifiedName);
            }

            if (resultRequired)
            {
                return ExecuteSingletonQuery(adapter, insertSql.ToString(), dataDictionary.Keys,
                                             dataDictionary.Values, transaction);
            }
            Execute(adapter, insertSql.ToString(), dataDictionary.Keys, dataDictionary.Values, transaction);
            return null;
        }
开发者ID:crmmvio,项目名称:Simple.Data,代码行数:34,代码来源:SqlCustomInserter.cs

示例5: Insert

        public IDictionary<string, object> Insert(AdoAdapter adapter, string tableName, IDictionary<string, object> data, IDbTransaction transaction = null,
            bool resultRequired = false)
        {
            var table = adapter.GetSchema().FindTable(tableName);

            var insertData = data.Where(p => table.HasColumn(p.Key)).Select((kv, idx) => new InsertColumn
            {
                Name = kv.Key,
                ParameterName = "@p" + idx,
                Value = kv.Value,
                Column = (FbColumn) table.FindColumn(kv.Key)
            }).ToArray();

            if (transaction == null)
            {
                using (var connection = adapter.ConnectionProvider.CreateConnection())
                {
                    connection.Open();
                    return CreateAndExecuteInsertCommand(connection, table, insertData, resultRequired);
                }
            }
            else
            {
                return CreateAndExecuteInsertCommand(transaction.Connection, table, insertData, resultRequired, transaction);
            }
            
        }
开发者ID:rafsawicki,项目名称:Simple.Data.Firebird,代码行数:27,代码来源:FbInserter.cs

示例6: Insert

        public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction)
        {
            var table = adapter.GetSchema().FindTable(tableName);
            var columns = table.Columns.Where(c => !c.IsIdentity).ToList();

            string columnList = string.Join(",", columns.Select(c => c.QuotedName));
            string valueList = string.Join(",", columns.Select(c => "?"));

            string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";

            var identityFunction = adapter.GetIdentityFunction();
            if (!string.IsNullOrWhiteSpace(identityFunction))
            {
                var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);

                if (identityColumn != null)
                {
                    var selectSql = "select * from " + table.QualifiedName + " where " + identityColumn.QuotedName +
                                     " = " + identityFunction;
                    if (adapter.ProviderSupportsCompoundStatements)
                    {
                        return InsertRowsWithCompoundStatement(adapter, data, transaction, table, columns, selectSql, insertSql);
                    }

                    return InsertRowsWithSeparateStatements(adapter, data, transaction, table, columns, insertSql, selectSql);
                }
            }

            InsertRowsWithoutFetchBack(adapter, data, table, columns, insertSql);

            return null;
        }
开发者ID:darrencauthon,项目名称:Simple.Data,代码行数:32,代码来源:BulkInserter.cs

示例7: QueryBuilder

 public QueryBuilder(AdoAdapter adoAdapter, int bulkIndex)
 {
     _adoAdapter = adoAdapter;
     _bulkIndex = bulkIndex;
     _schema = _adoAdapter.GetSchema();
     _commandBuilder = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder);
 }
开发者ID:basilrormose,项目名称:Simple.Data,代码行数:8,代码来源:QueryBuilder.cs

示例8: QueryBuilderBase

 protected QueryBuilderBase(AdoAdapter adapter, int bulkIndex, IFunctionNameConverter functionNameConverter)
 {
     _adoAdapter = adapter;
     _bulkIndex = bulkIndex;
     _schema = _adoAdapter.GetSchema();
     _commandBuilder = new CommandBuilder(_schema, _bulkIndex);
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema, _commandBuilder, functionNameConverter);
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:8,代码来源:QueryBuilderBase.cs

示例9: Update

        public int Update(AdoAdapter adapter, string tableName, IList<IDictionary<string, object>> data, IEnumerable<string> criteriaFieldNames, IDbTransaction transaction)
        {
            int count = 0;
            if (data == null || !data.Any()) 
                return count;

            var criteriaFieldNameList = criteriaFieldNames.ToList();
            if (criteriaFieldNameList.Count == 0) throw new NotSupportedException("Adapter does not support key-based update for this object.");

            if (!AllRowsHaveSameKeys(data)) throw new SimpleDataException("Records have different structures. Bulk updates are only valid on consistent records.");
            var table = adapter.GetSchema().FindTable(tableName);

            var exampleRow = new Dictionary<string, object>(data.First(), HomogenizedEqualityComparer.DefaultInstance);

            var commandBuilder = new UpdateHelper(adapter.GetSchema()).GetUpdateCommand(tableName, exampleRow,
                                                                    ExpressionHelper.CriteriaDictionaryToExpression(
                                                                        tableName, GetCriteria(criteriaFieldNameList, exampleRow)));

            var connection = adapter.CreateConnection();
            using (connection.MaybeDisposable())
            using (var command = commandBuilder.GetRepeatableCommand(connection))
            {
                if (transaction != null)
                {
                    command.Transaction = transaction;
                }
                connection.OpenIfClosed();
                var propertyToParameterMap = CreatePropertyToParameterMap(data, table, command);

                foreach (var row in data)
                {
                    foreach (var kvp in row)
                    {
                        if (propertyToParameterMap.ContainsKey(kvp.Key))
                        {
                            propertyToParameterMap[kvp.Key].Value = kvp.Value ?? DBNull.Value;
                        }
                    }
                    count += command.ExecuteNonQuery();
                }
            }

            return count;
        }
开发者ID:robertwilczynski,项目名称:Simple.Data,代码行数:44,代码来源:BulkUpdater.cs

示例10: GetDbCommand

        public IDbCommand GetDbCommand(AdoAdapter adapter, IDbConnection connection, IEnumerable<object> parameterValues)
        {
            var command = connection.CreateCommand(adapter.AdoOptions);
            command.CommandText = _commandText;

            foreach (var parameter in CreateParameters(adapter.GetSchema(), command, parameterValues))
            {
                command.Parameters.Add(parameter);
            }
            return command;
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:11,代码来源:CommandTemplate.cs

示例11: QueryBuilder

 public QueryBuilder(AdoAdapter adoAdapter)
 {
     _adoAdapter = adoAdapter;
     _schema = _adoAdapter.GetSchema();
 }
开发者ID:vansha,项目名称:Simple.Data,代码行数:5,代码来源:QueryBuilder.cs

示例12: QueryBuilder

 public QueryBuilder(AdoAdapter adoAdapter)
 {
     _adoAdapter = adoAdapter;
     _schema = _adoAdapter.GetSchema();
     _simpleReferenceFormatter = new SimpleReferenceFormatter(_schema);
 }
开发者ID:ciriarte,项目名称:Simple.Data,代码行数:6,代码来源:QueryBuilder.cs

示例13: Insert

        public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> dataList, IDbTransaction transaction, Func<IDictionary<string, object>, Exception, bool> onError,
            bool resultRequired)
        {
            //ToDo: support onError collection
            List<IDictionary<string, object>> result = new List<IDictionary<string, object>>();
          
            if (transaction == null)
            {
                adapter.InTransaction(currentTransaction =>
                {
                    result = (List<IDictionary<string, object>>) Insert(adapter, tableName, dataList, currentTransaction, onError, resultRequired);
                });
                return result;
            }


            var table = adapter.GetSchema().FindTable(tableName);
            var tableColumns = table.Columns.Select(c => (FbColumn)c).ToArray();
            var nameToFbColumns = tableColumns.ToDictionary(c => c.HomogenizedName, c => c);

            var insertContext = CreateInsertSqlContext(table.QualifiedName, tableColumns);

            var queryBuilder = new FbBulkInsertQueryBuilder(resultRequired, insertContext.ReturnsExecuteBlockSql);
            var insertSqlProvider = new FbBulkInsertSqlProvider();
            var currentColumns = new List<InsertColumn>();

            foreach (var data in dataList)
            {
                var insertData = data.Where(p => nameToFbColumns.ContainsKey(p.Key.Homogenize())).Select(kv => new InsertColumn
                {
                    Value = kv.Value,
                    Column =  nameToFbColumns[kv.Key.Homogenize()]
                }).ToArray();

                ExecuteBlockInsertSql insertSql = insertSqlProvider.GetInsertSql(insertContext, insertData, resultRequired);

                if (insertContext.SkipCommandParameters && !CanInsertInExecuteBlock(insertSql.InsertSql, queryBuilder))
                {
                    insertSql = insertSqlProvider.GetInsertSql(insertContext, insertData, resultRequired, skipCommandParameters: false); 
                }

                if (queryBuilder.CanAddQuery(insertSql))
                {
                    queryBuilder.AddQuery(insertSql);
                    if (!insertContext.SkipCommandParameters) currentColumns.AddRange(insertData);
                }
                else
                {
                    var subResult = CreateAndExecuteInsertCommand(transaction, currentColumns, queryBuilder.GetSql(), resultRequired);
                    if (resultRequired) result.AddRange(subResult);
                    currentColumns.Clear();

                    queryBuilder = new FbBulkInsertQueryBuilder(resultRequired, insertContext.ReturnsExecuteBlockSql);
                    queryBuilder.AddQuery(insertSql);
                    if (!insertContext.SkipCommandParameters) currentColumns.AddRange(insertData);
                }
            }

            if (queryBuilder.QueryCount > 0)
            {
                var subResult = CreateAndExecuteInsertCommand(transaction, currentColumns, queryBuilder.GetSql(), resultRequired);
                if (resultRequired) result.AddRange(subResult);
            }

            return result;
        }
开发者ID:rafsawicki,项目名称:Simple.Data.Firebird,代码行数:66,代码来源:FbBulkInserter.cs


注:本文中的Simple.Data.Ado.AdoAdapter.GetSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。