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


C# DatabaseContext.Commit方法代码示例

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


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

示例1: DeleteTest

        public void DeleteTest()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Delete<Warrior>();

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Delete));
            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:14,代码来源:DatabaseContextTests.cs

示例2: CommitTest

        public void CommitTest()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            var query = new Mock<IQueryCommand>();

            context.AddQuery(query.Object);

            Assert.IsTrue(context.QueryStore.Any());

            // Act
            context.Commit();

            Assert.IsFalse(context.QueryStore.Any());
            query.Verify(q => q.Execute(It.Is<IDatabaseContext>(c => c == context)), Times.Once);
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:16,代码来源:DatabaseContextTests.cs

示例3: SaveChunk

        private void SaveChunk(Chunk chunk)
        {
            using (var context = new DatabaseContext())
            {
                batch.ModifyChunk((Chunk)chunk, context);

                context.Commit();
            }
        }
开发者ID:szalaigj,项目名称:LoaderToolkit,代码行数:9,代码来源:Start.cs

示例4: LoadBatch

        private void LoadBatch()
        {
            using (var context = new DatabaseContext())
            {
                batch = new Batch();

                batch.BatchID = batchID;

                batch.Load(context);
                batch.LoadChunks(context);

                context.Commit();
            }
        }
开发者ID:szalaigj,项目名称:LoaderToolkit,代码行数:14,代码来源:Start.cs

示例5: Run

        public override void Run()
        {
            // Find files matching pattern
            var dir = Path.GetDirectoryName(Source);
            var pat = Path.GetFileName(Source);
            var ext = Path.GetExtension(Source);
            var files = Directory.GetFiles(dir, pat);

            var currentMapper = ObjectFactory.GetInstance<Mapper<string>>();
            if (!currentMapper.PreferredSourceFileExt.Equals(ext))
            {
                Console.WriteLine("WARNING: the extension of the given Source does not equal the " +
                    "preferred file extension of the given Mapper type! Are you sure you want to use it?");
            }

            if (files.Length == 0)
            {
                throw new ArgumentException("No files matching the source pattern were found.");
            }
            else
            {
                Console.WriteLine("Found {0} file(s), now creating batch...", files.Length);
            }

            var b = new Batch();

            using (var context = new DatabaseContext())
            {
                // Create batch object

                b.SourcePath = Path.GetDirectoryName(Source);
                b.FileSuffix = FileSuffix;
                b.ColumnOrders = ColumnOrders;
                b.BulkPath = BulkPath;

                b.TargetDB.DataSource = Server;
                b.TargetDB.InitialCatalog = TargetDB;
                b.TargetDB.IntegratedSecurity = IntegratedSecurity;
                if (!IntegratedSecurity)
                {
                    b.TargetDB.UserID = UserID;
                    b.TargetDB.Password = Password;
                }

                b.LoaderDB.DataSource = Server;
                b.LoaderDB.InitialCatalog = LoaderDB;
                b.LoaderDB.IntegratedSecurity = IntegratedSecurity;
                if (!IntegratedSecurity)
                {
                    b.LoaderDB.UserID = UserID;
                    b.LoaderDB.Password = Password;
                }

                b.Binary = binary;

                // Create chunks
                foreach (var f in files)
                {
                    var c = new Chunk();

                    c.ChunkId = Path.GetFileName(f);
                    b.Chunks.Add(c);
                }

                b.Save(context);
                b.CreateChunks(context);

                context.Commit();
            }

            Console.WriteLine("New batch created with ID {0}", b.BatchID);
        }
开发者ID:szalaigj,项目名称:LoaderToolkit,代码行数:72,代码来源:Create.cs

示例6: LoadRelatedRefIDsFromDB

 private Dictionary<string, int> LoadRelatedRefIDsFromDB()
 {
     Dictionary<string, int> result = new Dictionary<string, int>();
     using (var context = new DatabaseContext())
     {
         string sql = queryForRefIds;
         sql = sql.Replace("$targetdb", targetDB);
         sql = sql.Replace("$speciesID", speciesID.ToString());
         using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction))
         {
             using (var dr = cmd.ExecuteReader())
             {
                 while (dr.Read())
                 {
                     LoadFromDataReader(dr, result);
                 }
             }
         }
         context.Commit();
     }
     return result;
 }
开发者ID:szalaigj,项目名称:LoaderToolkit,代码行数:22,代码来源:SamAdapt.cs

示例7: DeleteWithConditionDefinedInAnonymObject

        public void DeleteWithConditionDefinedInAnonymObject()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Delete<Warrior>(() => new { ID = 1 });

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Delete));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Where));
            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:15,代码来源:DatabaseContextTests.cs

示例8: UpdateWithTableTypeObjectAndId

        public void UpdateWithTableTypeObjectAndId()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Update(() => new Warrior { ID = 1, Name = "Wrir" }, w => w.ID);

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Update));
            //Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Set));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Where));

            // update all properties except id
            Assert.IsTrue(expression.QueryParts.Parts.Where(p => p.OperationType == OperationType.Update).OfType<DelegateQueryPart>().First().Parts.Count() == 4);

            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:20,代码来源:DatabaseContextTests.cs

示例9: UpdateWithAnonymObjectAndCondition

        public void UpdateWithAnonymObjectAndCondition()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Update<Warrior>(() => new { Name = "test" }, w => w.ID == 1);

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Update));
            //Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Set));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Where));

            Assert.IsTrue(expression.QueryParts.Parts.Where(p => p.OperationType == OperationType.Update).OfType<DelegateQueryPart>().First().Parts.Count() == 1);

            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:19,代码来源:DatabaseContextTests.cs

示例10: InserWithTableTypeDataObject

        public void InserWithTableTypeDataObject()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Insert(() => new Warrior { ID = 1, Name = "test" });

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Insert));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Values));
            Assert.IsTrue(expression.QueryParts.Parts.Where(p => p.OperationType == OperationType.Values).First().Parts.Count() == 5);
            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:16,代码来源:DatabaseContextTests.cs

示例11: InsertWithAnonymDataObject

        public void InsertWithAnonymDataObject()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Insert<Warrior>(() => new { ID = 1, Name = "test" });

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Insert));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Values));

            // only insert the properties that are provided
            Assert.IsTrue(expression.QueryParts.Parts.Where(p => p.OperationType == OperationType.Values).First().Parts.Count() == 2);

            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:19,代码来源:DatabaseContextTests.cs

示例12: DeleteWithDataObjectAndIdParameter

        public void DeleteWithDataObjectAndIdParameter()
        {
            var context = new DatabaseContext(_provider.Object, _settings.Object);

            // Act
            var expression = context.Delete(() => new Warrior { ID = 1 }, w => w.ID);

            Assert.IsNotNull(expression);
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Delete));
            Assert.IsTrue(expression.QueryParts.Parts.Any(p => p.OperationType == OperationType.Where));
            Assert.IsTrue(context.QueryStore.Any());

            context.Commit();
            Assert.IsFalse(context.QueryStore.Any());
        }
开发者ID:chriswalpen,项目名称:PersistenceMap,代码行数:15,代码来源:DatabaseContextTests.cs


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