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


C# DataContext.ExecuteCommand方法代码示例

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


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

示例1: 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

示例2: ClearTpDB

		private static void ClearTpDB(DataContext tpDatabaseDataContext)
		{
            if (!tpDatabaseDataContext.DatabaseExists())
            {
                tpDatabaseDataContext.CreateDatabase();
                tpDatabaseDataContext.SubmitChanges();
            }
            else
            {
                tpDatabaseDataContext.ExecuteCommand("delete from Project");
                tpDatabaseDataContext.ExecuteCommand("delete from TpUser");
                tpDatabaseDataContext.ExecuteCommand("delete from General");
                tpDatabaseDataContext.ExecuteCommand("delete from MessageUid");
                tpDatabaseDataContext.ExecuteCommand("delete from PluginProfile");
                tpDatabaseDataContext.ExecuteCommand("delete from Revision");  
            }
		}
开发者ID:sbcfwebdev,项目名称:Target-Process-Plugins,代码行数:17,代码来源:LegacyProfileConversionActionSteps.cs

示例3: ClearTpDB

		private static void ClearTpDB(DataContext tpDatabaseDataContext)
		{
			tpDatabaseDataContext.ExecuteCommand("delete from Project");
			tpDatabaseDataContext.ExecuteCommand("delete from CustomReport");
			tpDatabaseDataContext.ExecuteCommand("delete from TpUser");
			tpDatabaseDataContext.ExecuteCommand("delete from General");
			tpDatabaseDataContext.ExecuteCommand("delete from MessageUid");
			tpDatabaseDataContext.ExecuteCommand("delete from PluginProfile");
			tpDatabaseDataContext.ExecuteCommand("delete from Revision");
		}
开发者ID:sbcfwebdev,项目名称:Target-Process-Plugins,代码行数:10,代码来源:LegacyProfileConversionActionSteps.cs

示例4: Form1

        public Form1()
        {
            InitializeComponent();

            string connString = "DataSource=db/Pots.db3;";
            SQLiteConnection connection = new SQLiteConnection(connString);
            DataContext = new DataContext(connection);
            DataContext.ExecuteCommand("PRAGMA foreign_keys=ON;");
            formEditor = new FormEditor();
            diagramView1.OnItemSelect += (obj, index) =>
                {
                    propertyGrid1.SelectedObject = obj;
                };
            buttonRefresh_Click(null, null);
        }
开发者ID:YaStark,项目名称:Pots,代码行数:15,代码来源:Form1.cs

示例5: ReCreateDatabaseFromAttributeMapping

        protected void ReCreateDatabaseFromAttributeMapping(DataContext ctx)
        {
            bool success = false;
            bool retry = false;
            int retries = 0;
            do
            {
                try
                {
                    using (ctx)
                    {
                        CloseAllOpenConnections(ctx);
                        ctx.Log = new StringWriter();

                        if (ctx.DatabaseExists())
                        {
                            //drop all connections by disabling multi-user (and immediatly abort all current transactions)
                            ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
                            ctx.DeleteDatabase();
                        }
                        try
                        {
                            ctx.CreateDatabase();
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e);
                            Debug.WriteLine(ctx.Log);
                            throw;
                        }

                        //re-enable multi-user (again)
                        ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET MULTI_USER");
                        success = true;
                    }
                }
                catch (SqlException e)
                {
                    retry = false;
                    if (e.Message.IndexOf("was deadlocked on lock resources with another process and has been chosen as the deadlock victim") > 0)
                    {
                        retry = true;
                        retries++;
                    }
                }
            } while (success == false && (retry && retries < 3));
        }
开发者ID:consumentor,项目名称:Server,代码行数:47,代码来源:DatabaseSpecBase.cs

示例6: PutMessage

        public void PutMessage(ImmutableEnvelope envelope)
        {
            var buffer = _streamer.SaveEnvelopeData(envelope);
            var now = DateTime.UtcNow;

            using (var db = new DataContext(_connectionString))
            {
                db.ExecuteCommand
                (
                    "exec [dbo].[Enqueue] {0}, {1}, {2}, {3}, {4}",
                    _queueID,
                    envelope.EnvelopeId,
                    envelope.CreatedOnUtc,
                    envelope.DeliverOnUtc < now ? now : envelope.DeliverOnUtc,
                    buffer
                );
            }
        }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:18,代码来源:StatelessSqlQueueWriter.cs

示例7: SendToPoisonQueue

 void SendToPoisonQueue(QueueMessage message)
 {
     using (var db = new DataContext(_config.ConnectionString))
     {
         db.ExecuteCommand
         (
             "exec [dbo].[Enqueue] {0}, {1}, {2}, {3}, {4}",
             _poisonQueueID,
             message.EnvelopeID,
             message.CreatedOnUtc,
             DateTime.UtcNow,
             message.Envelope
         );
     }
 }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:15,代码来源:StatelessSqlQueueReader.cs

示例8: DeleteMessage

 void DeleteMessage(QueueMessage message)
 {
     using (var db = new DataContext(_config.ConnectionString))
     {
         db.ExecuteCommand
         (
             "exec [dbo].[Delete] {0}",
             message.MessageID
         );
     }
 }
开发者ID:xpando,项目名称:lokad-cqrs,代码行数:11,代码来源:StatelessSqlQueueReader.cs

示例9: RemoveDb

        private void RemoveDb()
        {
            var config =  DependencyResolver.Current.GetService<IConfig>();

            var db = new DataContext(config.ConnectionStrings("ConnectionString"));

            var textCloseConnectionTestDb = string.Format(@"ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", TestDbName);
            db.ExecuteCommand(textCloseConnectionTestDb);

            var textDropTestDb = string.Format(@"DROP DATABASE [{0}]", TestDbName);
            db.ExecuteCommand(textDropTestDb);
        }
开发者ID:jorik041,项目名称:lessons-asp-mvc,代码行数:12,代码来源:IntegratedTestSetupFixture.cs

示例10: CreateTable

        /// <summary>  
        /// 创建单个表  
        /// </summary>  
        /// <param name="linqTableClass"></param>
        /// <param name="db"></param>  
        private static void CreateTable(Type linqTableClass, DataContext db)
        {
            var metaTable = db.Mapping.GetTable(linqTableClass);
            //反射的方法创建对象
            var typeName = "System.Data.Linq.SqlClient.SqlBuilder";
            var type = typeof(DataContext).Assembly.GetType(typeName);

            //反射调用私有的GetCreateTableCommand 方法。
            var bf = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
            var sql = type.InvokeMember("GetCreateTableCommand", bf, null, null, new[] { metaTable });

            var sqlAsString = sql.ToString();
            db.ExecuteCommand(sqlAsString);
        }
开发者ID:yjk282,项目名称:YUI,代码行数:19,代码来源:CallInfo.cs


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