本文整理汇总了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();
}
}
示例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()
};
}
}
示例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);
}
示例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();
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
}