本文整理汇总了C#中Table.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Select方法的具体用法?C# Table.Select怎么用?C# Table.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LinqUdt_Select
public void LinqUdt_Select()
{
var table = new Table<Album>(_session, new MappingConfiguration().Define(new Map<Album>().TableName("albums")));
var album = table.Select(a => new Album { Id = a.Id, Name = a.Name, Songs = a.Songs }).Execute().First();
Assert.AreEqual(_sampleId, album.Id);
Assert.AreEqual("Legend", album.Name);
Assert.NotNull(album.Songs);
Assert.AreEqual(1, album.Songs.Count);
var song = album.Songs[0];
Assert.AreEqual("Africa Unite", song.Title);
Assert.AreEqual("Bob Marley", song.Artist);
}
示例2: 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);
}
示例3: LinqAttributes_Counter
public void LinqAttributes_Counter()
{
//var mapping = new Map<PocoWithCounter>();
var mappingConfig = new MappingConfiguration();
mappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(CounterEntityWithLinqAttributes),
() => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(CounterEntityWithLinqAttributes)));
var table = new Table<CounterEntityWithLinqAttributes>(_session, mappingConfig);
table.Create();
List<CounterEntityWithLinqAttributes> counterPocos = new List<CounterEntityWithLinqAttributes>();
for (int i = 0; i < 10; i++)
{
counterPocos.Add(
new CounterEntityWithLinqAttributes()
{
KeyPart1 = Guid.NewGuid(),
KeyPart2 = (decimal)123,
});
}
int counterIncrements = 100;
string updateStr = String.Format("UPDATE \"{0}\" SET \"{1}\"=\"{1}\" + 1 WHERE \"{2}\"=? and \"{3}\"=?", typeof(CounterEntityWithLinqAttributes).Name, "Counter", "KeyPart1", "KeyPart2");
var updateSession = _session.Prepare(updateStr);
foreach (CounterEntityWithLinqAttributes pocoWithCounter in counterPocos)
{
var boundStatement = updateSession.Bind(new object[] { pocoWithCounter.KeyPart1, pocoWithCounter.KeyPart2 });
for (int j = 0; j < counterIncrements; j++)
_session.Execute(boundStatement);
pocoWithCounter.Counter += counterIncrements;
}
List<CounterEntityWithLinqAttributes> countersQueried = table.Select(m => m).Execute().ToList();
foreach (CounterEntityWithLinqAttributes pocoWithCounterExpected in counterPocos)
{
bool counterFound = false;
foreach (CounterEntityWithLinqAttributes pocoWithCounterActual in countersQueried)
{
if (pocoWithCounterExpected.KeyPart1 == pocoWithCounterActual.KeyPart1)
{
Assert.AreEqual(pocoWithCounterExpected.KeyPart2, pocoWithCounterExpected.KeyPart2);
Assert.AreEqual(pocoWithCounterExpected.Counter, pocoWithCounterExpected.Counter);
counterFound = true;
}
}
Assert.IsTrue(counterFound, "Counter with first key part: " + pocoWithCounterExpected.KeyPart1 + " was not found!");
}
}
示例4: LinqUdt_Select
public void LinqUdt_Select()
{
// Avoid interfering with other tests
_session.Execute("DROP TABLE IF EXISTS albums");
_session.Execute("CREATE TABLE albums (id uuid primary key, name text, songs list<frozen<song>>, publishingdate timestamp)");
_session.Execute(
new SimpleStatement(
"INSERT INTO albums (id, name, songs) VALUES (?, 'Legend', [{id: uuid(), title: 'Africa Unite', artist: 'Bob Marley'}])",
_sampleId));
var table = new Table<Album>(_session, new MappingConfiguration().Define(new Map<Album>().TableName("albums")));
var album = table.Select(a => new Album { Id = a.Id, Name = a.Name, Songs = a.Songs }).Execute().First();
Assert.AreEqual(_sampleId, album.Id);
Assert.AreEqual("Legend", album.Name);
Assert.NotNull(album.Songs);
Assert.AreEqual(1, album.Songs.Count);
var song = album.Songs[0];
Assert.AreEqual("Africa Unite", song.Title);
Assert.AreEqual("Bob Marley", song.Artist);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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());
}
示例9: DeleteIf_NoMatchingRecord
public void DeleteIf_NoMatchingRecord()
{
// 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.StringType == entityToDelete.StringType + Randomm.RandomAlphaNum(10) && m.GuidType == Guid.NewGuid());
var deleteIfQuery = selectQuery.DeleteIf(m => m.IntType == entityToDelete.IntType);
var appliedInfo = deleteIfQuery.Execute();
Assert.False(appliedInfo.Applied);
}
示例10: 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);
}
示例11: 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);
Assert.Throws<InvalidQueryException>(() => deleteIfQuery.Execute());
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: replaceSpaces
protected void replaceSpaces(Table table)
{
table.Select();
app.Selection.Find.Execute(FindText: " ", MatchCase: false, ReplaceWith: "^s", Replace: WdReplace.wdReplaceAll);
}