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


C# Table.Count方法代码示例

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


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

示例1: AddAndGetNumKey

        public void AddAndGetNumKey()
        {
            var ta = new Table();

            Assert.AreEqual( 0, ta.Count() );

            ta[1] = 213;

            Assert.AreEqual( 213, ta[1] );
            Assert.AreEqual( 1, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[Math.PI] );
            Assert.AreEqual( 213, ta[1] );

            ta[1] = Value.Nil;

            Assert.AreEqual( 0, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[1] );

            ta[Math.PI] = 213;

            Assert.AreEqual( 213, ta[Math.PI] );
            Assert.AreEqual( 1, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[1] );
            Assert.AreEqual( 213, ta[Math.PI] );

            ta[Math.PI] = Value.Nil;

            Assert.AreEqual( 0, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[Math.PI] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:30,代码来源:TableTests.cs

示例2: Delete_DeleteMultipleContains_Sync

        public void Delete_DeleteMultipleContains_Sync()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);

            List<string> uniqueStringKeys = _entityList.Select(m => m.StringType).ToList();
            var deleteRequest = table.Where(m => uniqueStringKeys.Contains(m.StringType)).Delete();
            deleteRequest.Execute();
            count = table.Count().Execute();
            Assert.AreEqual(0, count);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:12,代码来源:Delete.cs

示例3: Delete_DeleteOneViaEquals_Async

        public void Delete_DeleteOneViaEquals_Async()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];

            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery = selectQuery.Delete();

            deleteQuery.ExecuteAsync().Result.ToList();
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count - 1, count);
            Assert.AreEqual(0, selectQuery.Execute().ToList().Count);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:15,代码来源:Delete.cs

示例4: AddAndGetStringKey

        public void AddAndGetStringKey()
        {
            var sa1 = new LString( "A" );
            var sa2 = new LString( "A" );
            var sb = new LString( "B" );

            var ta = new Table();

            Assert.AreEqual( 0, ta.Count() );

            ta[sa1] = 213;

            Assert.AreEqual( 213, ta[sa1] );
            Assert.AreEqual( 213, ta[sa2] );
            Assert.AreEqual( 1, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[sb] );
            Assert.AreEqual( 213, ta[sa1] );

            ta[sa1] = Value.Nil;

            Assert.AreEqual( 0, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[sa1] );

            ta[sb] = 2354;

            Assert.AreEqual( 2354, ta[sb] );
            Assert.AreEqual( 1, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[sa2] );
            Assert.AreEqual( 2354, ta[sb] );

            ta[sb] = Value.Nil;

            Assert.AreEqual( 0, ta.Count() );
            Assert.AreEqual( Value.Nil, ta[sb] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:35,代码来源:TableTests.cs

示例5: DeleteIf_ConditionSucceeds

        public void DeleteIf_ConditionSucceeds()
        {
            var table = new Table<Movie>(_session, new MappingConfiguration());
            table.Create();
            Movie actualMovie = Movie.GetRandomMovie();
            table.Insert(actualMovie).Execute();
            long count = table.Count().Execute();
            Assert.AreEqual(1, count);

            var deleteIfStatement = table
                .Where(m => m.Title == actualMovie.Title && m.MovieMaker == actualMovie.MovieMaker && m.Director == actualMovie.Director)
                .DeleteIf(m => m.MainActor == actualMovie.MainActor);

            var appliedInfo = deleteIfStatement.Execute();
            Assert.True(appliedInfo.Applied);
            Assert.Null(appliedInfo.Existing);
            count = table.Count().Execute();
            Assert.AreEqual(0, count);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:19,代码来源:DeleteIf.cs

示例6: AddAndGetBoolKey

        public void AddAndGetBoolKey()
        {
            var ta = new Table();

            Assert.AreEqual( 0, ta.Count() );

            ta[true] = 213;
            Assert.AreEqual( 213, ta[true] );

            Assert.AreEqual( 1, ta.Count() );

            Assert.AreEqual( Value.Nil, ta[false] );

            Assert.AreEqual( 213, ta[true] );

            ta[true] = Value.Nil;

            Assert.AreEqual( 0, ta.Count() );

            Assert.AreEqual( Value.Nil, ta[true] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:21,代码来源:TableTests.cs

示例7: SetupTest

        public void SetupTest()
        {
            _session = TestClusterManager.GetTestCluster(1).Session;
            _session.CreateKeyspace(_uniqueKsName);
            _session.ChangeKeyspace(_uniqueKsName);

            // drop table if exists, re-create
            MappingConfiguration movieMappingConfig = new MappingConfiguration();
            movieMappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(Movie),
                 () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(Movie)));
            _movieTable = new Table<Movie>(_session, movieMappingConfig);
            _movieTable.Create();

            //Insert some data
            foreach (var movie in _movieList)
                _movieTable.Insert(movie).Execute();

            // Wait for data to be query-able
            DateTime futureDateTime = DateTime.Now.AddSeconds(2); // it should not take very long for these records to become available for querying!
            while (DateTime.Now < futureDateTime && _movieTable.Count().Execute() < _movieList.Count)
                Thread.Sleep(200);
            Assert.AreEqual(_movieList.Count(), _movieTable.Count().Execute(), "Setup failure: Expected number of records are not query-able");
        }
开发者ID:raideroflostark,项目名称:csharp-driver,代码行数:23,代码来源:First.cs

示例8: DeleteIf_ConditionBasedOnKey

 public void DeleteIf_ConditionBasedOnKey()
 {
     var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
     var count = table.Count().Execute();
     Assert.AreEqual(_entityList.Count, count);
     AllDataTypesEntity entityToDelete = _entityList[0];
     var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
     var deleteIfQuery = selectQuery.DeleteIf(m => m.StringType == entityToDelete.StringType);
     try
     {
         deleteIfQuery.Execute();
         Assert.Fail("Expected exception was not thrown!");
     }
     catch (InvalidQueryException e)
     {
         string expectedErrMsg = "PRIMARY KEY column 'string_type' cannot have IF conditions";
         Assert.AreEqual(expectedErrMsg, e.Message);
     }
     // make sure record was not deleted
     count = table.Count().Execute();
     Assert.AreEqual(_entityList.Count, count);
     List<AllDataTypesEntity> rows = selectQuery.Execute().ToList();
     Assert.AreEqual(1, rows.Count);
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:24,代码来源:DeleteIf.cs

示例9: Delete_MissingKey_Sync

        public void Delete_MissingKey_Sync()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);

            var selectQuery = table.Select(m => m).Where(m => m.BooleanType == true);
            var deleteQuery = selectQuery.Delete();

            var ex = Assert.Throws<InvalidQueryException>(() => deleteQuery.Execute());
            StringAssert.Contains("Non PRIMARY KEY boolean_type found in where clause", ex.Message);
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:12,代码来源:Delete.cs

示例10: Delete_IfExists_ClusteringKeyOmitted

        public void Delete_IfExists_ClusteringKeyOmitted()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];

            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery = selectQuery.Delete().IfExists();

            Assert.Throws<InvalidQueryException>(() => deleteQuery.Execute());

            // make sure record was not deleted
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:16,代码来源:Delete.cs

示例11: Delete_IfExists_RowDoesntExist

        public void Delete_IfExists_RowDoesntExist()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];

            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType && m.GuidType == entityToDelete.GuidType);
            var deleteQuery = selectQuery.Delete().IfExists();

            deleteQuery.Execute();
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count - 1, count);
            Assert.AreEqual(0, selectQuery.Execute().ToList().Count);

            // Executing again should not fail, should just be a no-op
            deleteQuery.Execute();
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count - 1, count);
            Assert.AreEqual(0, selectQuery.Execute().ToList().Count);

        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:22,代码来源:Delete.cs

示例12: Delete_NoSuchRecord

        public void Delete_NoSuchRecord()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];
            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType + Randomm.RandomAlphaNum(16));
            var deleteQuery = selectQuery.Delete();
            deleteQuery.Execute();

            // make sure record was not deleted
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            List<AllDataTypesEntity> rows = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType).Execute().ToList();
            Assert.AreEqual(1, rows.Count);
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:16,代码来源:Delete.cs

示例13: Delete_MissingKey_Sync

        public void Delete_MissingKey_Sync()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);

            var selectQuery = table.Select(m => m).Where(m => m.BooleanType == true);
            var deleteQuery = selectQuery.Delete();

            Assert.Throws<InvalidQueryException>(() => deleteQuery.Execute());
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:11,代码来源:Delete.cs

示例14: Delete_IfExists_ClusteringKeyOmitted

        public void Delete_IfExists_ClusteringKeyOmitted()
        {
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];

            var selectQuery = table.Select(m => m).Where(m => m.StringType == entityToDelete.StringType);
            var deleteQuery = selectQuery.Delete().IfExists();

            var ex = Assert.Throws<InvalidQueryException>(() => deleteQuery.Execute());
            StringAssert.Contains(
                "DELETE statements must restrict all PRIMARY KEY columns with equality relations in order to use IF conditions, but column 'guid_type' is not restricted",
                ex.Message);

            // make sure record was not deleted
            count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:19,代码来源:Delete.cs

示例15: DeleteIf_NotAllKeysRestricted_PartitionKeyOmitted

        public void DeleteIf_NotAllKeysRestricted_PartitionKeyOmitted()
        {
            // Validate pre-test state
            var table = new Table<AllDataTypesEntity>(_session, new MappingConfiguration());
            var count = table.Count().Execute();
            Assert.AreEqual(_entityList.Count, count);
            AllDataTypesEntity entityToDelete = _entityList[0];

            // Test
            var selectQuery = table.Select(m => m).Where(m => m.GuidType == Guid.NewGuid());
            var deleteIfQuery = selectQuery.DeleteIf(m => m.IntType == entityToDelete.IntType);

            var ex = Assert.Throws<InvalidQueryException>(() => deleteIfQuery.Execute());
            StringAssert.Contains(
                "DELETE statements must restrict all PRIMARY KEY columns with equality relations in order to use IF conditions, but column 'string_type' is not restricted",
                ex.Message);
        }
开发者ID:Virus-X,项目名称:csharp-driver,代码行数:17,代码来源:DeleteIf.cs


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