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


C# DataContext.ExecuteQuery方法代码示例

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


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

示例1: Initialize

 public void Initialize()
 {
     using (var db = new DataContext(_config.ConnectionString))
     {
         _queueID       = db.ExecuteQuery<int>("exec [dbo].[GetQueueID] {0}", _queueName).Single();
         _poisonQueueID = db.ExecuteQuery<int>("exec [dbo].[GetQueueID] {0}", _queueName + "_Poison").Single();
     }
 }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:8,代码来源:StatelessSqlQueueReader.cs

示例2: GetSchemaInformation

 /// <summary>
 /// Queries the target database specified by the SqlConnection for schema information.
 /// </summary>
 private static SchemaDiscoveryResult GetSchemaInformation(SqlConnection connection)
 {
     using (DataContext context = new DataContext(connection))
     {
         return new SchemaDiscoveryResult
         {
             DatabaseName = connection.Database,
             Objects = context.ExecuteQuery<DbObject>(SqlObjectsQuery).ToList(),
             Columns = context.ExecuteQuery<DbColumn>(SqlColumnsQuery).ToList(),
             Indexes = context.ExecuteQuery<DbIndex>(SqlIndexesQuery).ToList()
         };
     }
 }
开发者ID:nelsonad,项目名称:SqlSchemaCompare,代码行数:16,代码来源:DatabaseSchemaService.cs

示例3: CopyDb

        private void CopyDb(StandardKernel kernel, out FileInfo sandboxFile, out string connectionString)
        {
            var config = kernel.Get<IConfig>();
            var db = new DataContext(config.ConnectionStrings("ConnectionString"));

            TestDbName = string.Format("{0}_{1}", NameDb, DateTime.Now.ToString("yyyyMMdd_HHmmss"));
            sandboxFile = new FileInfo(string.Format("{0}\\{1}.bak", Sandbox, TestDbName));
            var sandboxDir = new DirectoryInfo(Sandbox);

            //backupFile
            var textBackUp = string.Format(@"-- Backup the database
            BACKUP DATABASE [{0}]
            TO DISK = '{1}'
            WITH COPY_ONLY",
            NameDb, sandboxFile.FullName);
            db.ExecuteCommand(textBackUp);

            var restoreFileList = string.Format("RESTORE FILELISTONLY FROM DISK = '{0}'", sandboxFile.FullName);
            var fileListRestores = db.ExecuteQuery<FileListRestore>(restoreFileList).ToList();
            var logicalDbName = fileListRestores.FirstOrDefault(p => p.Type == "D");
            var logicalLogDbName = fileListRestores.FirstOrDefault(p => p.Type == "L");

            var restoreDb = string.Format("RESTORE DATABASE [{0}] FROM DISK = '{1}' WITH FILE = 1, MOVE N'{2}' TO N'{4}\\{0}.mdf', MOVE N'{3}' TO N'{4}\\{0}.ldf', NOUNLOAD, STATS = 10", TestDbName, sandboxFile.FullName, logicalDbName.LogicalName, logicalLogDbName.LogicalName, sandboxDir.FullName);
            db.ExecuteCommand(restoreDb);

            connectionString = config.ConnectionStrings("ConnectionString").Replace(NameDb, TestDbName);
        }
开发者ID:jorik041,项目名称:lessons-asp-mvc,代码行数:27,代码来源:IntegratedTestSetupFixture.cs

示例4: StatelessSqlQueueWriter

        public StatelessSqlQueueWriter(
            IEnvelopeStreamer streamer, 
            string connectionString, 
            string name
        )
        {
            _streamer         = streamer;
            _connectionString = connectionString;
            Name              = name;

            using (var db = new DataContext(_connectionString))
            {
                _queueID = db.ExecuteQuery<int>("exec [dbo].[GetQueueID] {0}", name).Single();
            }
        }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:15,代码来源:StatelessSqlQueueWriter.cs

示例5: ExecuteQuery

        public Common.Execution.QueryResult ExecuteQuery(String script)
        {
            var fullScript = String.Format("exec {0}", script);

            Common.Execution.QueryResult executionResult;

            try
            {
                using (var context = new DataContext(_connectionString))
                {
                    var result = context.ExecuteQuery<Int32>(fullScript);

                    executionResult = Common.Execution.QueryResult.CreateSuccessfulResult(result);
                }
            }
            catch (Exception exception)
            {
                executionResult = Common.Execution.QueryResult.CreateFailResult(exception);
            }

            return executionResult;
        }
开发者ID:richRubie,项目名称:Databasepatcher,代码行数:22,代码来源:SqlExecuter.cs

示例6: SetPrimaryKeyNames

 public void SetPrimaryKeyNames(DataContext context)
 {
     this.PrimaryKeyNames = context.ExecuteQuery<string>("SELECT column_name as ColumnName FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1 AND table_name = {0}", this.TableName).ToList();
 }
开发者ID:Allen-Wei,项目名称:Alan.RepositoryGenerateToolkit,代码行数:4,代码来源:TableModel.cs

示例7: SetIdentityColumnNames

 public void SetIdentityColumnNames(DataContext context)
 {
     this.IdentityColumnNames = context.ExecuteQuery<string>("select Name from sys.identity_columns where object_name(object_id) = {0}", this.TableName).ToList();
 }
开发者ID:Allen-Wei,项目名称:Alan.RepositoryGenerateToolkit,代码行数:4,代码来源:TableModel.cs

示例8: TryGetMessage

        public GetEnvelopeResult TryGetMessage()
        {
            QueueMessage message;

            try
            {
                using (var db = new DataContext(_config.ConnectionString))
                {
                    message = db
                        .ExecuteQuery<QueueMessage>
                        (
                            "exec [dbo].[Dequeue] {0}, {1}, {2}",
                            _queueID,
                            _visibilityTimeout.TotalSeconds,
                            1
                        )
                        .FirstOrDefault();
                }
            }
            catch(Exception ex)
            {
                _observer.Notify(new FailedToReadMessage(ex, _queueName));
                return GetEnvelopeResult.Error();
            }

            if (message == null)
                return GetEnvelopeResult.Empty;

            try
            {
                var envelope = _streamer.ReadAsEnvelopeData(message.Envelope.ToArray());
                var context = new EnvelopeTransportContext(message, envelope, _queueName);
                return GetEnvelopeResult.Success(context);
            }
            catch(Exception ex)
            {
                _observer.Notify(new EnvelopeDeserializationFailed(ex, _queueName, message.EnvelopeID));
                SendToPoisonQueue(message);
                DeleteMessage(message);
                return GetEnvelopeResult.Retry;
            }
        }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:42,代码来源:StatelessSqlQueueReader.cs


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