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