本文整理汇总了C#中Table.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Execute方法的具体用法?C# Table.Execute怎么用?C# Table.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.Execute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Linq_CqlQueryBase_Execute_Maps_Rows
public void Linq_CqlQueryBase_Execute_Maps_Rows()
{
var usersExpected = TestDataHelper.GetUserList();
var table = new Table<PlainUser>(GetSession(TestDataHelper.GetUsersRowSet(usersExpected)));
var users = table.Execute().ToList();
CollectionAssert.AreEqual(usersExpected, users, new TestHelper.PropertyComparer());
}
示例2: LinqUpdate_Single
public void LinqUpdate_Single()
{
// Setup
Table<Movie> table = new Table<Movie>(_session, new MappingConfiguration());
table.CreateIfNotExists();
Movie movieToUpdate = _movieList[1];
var expectedMovie = new Movie(movieToUpdate.Title, movieToUpdate.Director, "something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate.MovieMaker, 1212);
table.Where(m => m.Title == movieToUpdate.Title && m.MovieMaker == movieToUpdate.MovieMaker && m.Director == movieToUpdate.Director)
.Select(m => new Movie { Year = expectedMovie.Year, MainActor = expectedMovie.MainActor })
.Update()
.Execute();
List<Movie> actualMovieList = table.Execute().ToList();
Assert.AreEqual(_movieList.Count, actualMovieList.Count());
Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie));
Movie.AssertListContains(actualMovieList, expectedMovie);
}
示例3: LinqUpdate_Batch
public void LinqUpdate_Batch()
{
// Setup
Table<Movie> table = new Table<Movie>(_session, new MappingConfiguration());
table.CreateIfNotExists();
Movie movieToUpdate1 = _movieList[1];
Movie movieToUpdate2 = _movieList[2];
BatchStatement batch = new BatchStatement();
var expectedMovie1 = new Movie(movieToUpdate1.Title, movieToUpdate1.Director, "something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate1.MovieMaker, 1212);
var update1 = table.Where(m => m.Title == movieToUpdate1.Title && m.MovieMaker == movieToUpdate1.MovieMaker && m.Director == movieToUpdate1.Director)
.Select(m => new Movie { Year = expectedMovie1.Year, MainActor = expectedMovie1.MainActor })
.Update();
batch.Add(update1);
var expectedMovie2 = new Movie(movieToUpdate2.Title, movieToUpdate2.Director, "also_something_different_" + Randomm.RandomAlphaNum(10), movieToUpdate2.MovieMaker, 1212);
var update2 = table.Where(m => m.Title == movieToUpdate2.Title && m.MovieMaker == movieToUpdate2.MovieMaker && m.Director == movieToUpdate2.Director)
.Select(m => new Movie { Year = expectedMovie2.Year, MainActor = expectedMovie2.MainActor })
.Update();
batch.Add(update2);
table.GetSession().Execute(batch);
List<Movie> actualMovieList = table.Execute().ToList();
Assert.AreEqual(_movieList.Count, actualMovieList.Count());
Assert.AreNotEqual(expectedMovie1.MainActor, expectedMovie2.MainActor);
Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie1));
Assert.IsFalse(Movie.ListContains(_movieList, expectedMovie2));
Movie.AssertListContains(actualMovieList, expectedMovie1);
Movie.AssertListContains(actualMovieList, expectedMovie2);
}
示例4: Linq_CqlQueryBase_Execute_SingleColumn_Rows
public void Linq_CqlQueryBase_Execute_SingleColumn_Rows()
{
var table = new Table<int>(GetSession(TestDataHelper.GetSingleValueRowSet("int_val", 1)));
var result = table.Execute().ToList();
CollectionAssert.AreEqual(new[] { 1 }, result.ToArray(), new TestHelper.PropertyComparer());
}
示例5: Linq_CqlQuery_Automatically_Pages
public void Linq_CqlQuery_Automatically_Pages()
{
const int pageLength = 100;
var rs = TestDataHelper.GetSingleColumnRowSet("int_val", Enumerable.Repeat(1, pageLength).ToArray());
BoundStatement stmt = null;
var sessionMock = new Mock<ISession>(MockBehavior.Strict);
sessionMock
.Setup(s => s.ExecuteAsync(It.IsAny<BoundStatement>()))
.Returns(TestHelper.DelayedTask(rs))
.Callback<IStatement>(s => stmt = (BoundStatement)s)
.Verifiable();
sessionMock.Setup(s => s.PrepareAsync(It.IsAny<string>())).Returns(TaskHelper.ToTask(GetPrepared("Mock query")));
sessionMock.Setup(s => s.BinaryProtocolVersion).Returns(2);
rs.AutoPage = true;
rs.PagingState = new byte[] { 0, 0, 0 };
var counter = 0;
rs.FetchNextPage = state =>
{
var rs2 = TestDataHelper.GetSingleColumnRowSet("int_val", Enumerable.Repeat(1, pageLength).ToArray());
if (++counter < 2)
{
rs2.PagingState = new byte[] {0, 0, (byte) counter};
}
return rs2;
};
var table = new Table<int>(sessionMock.Object);
IEnumerable<int> results = table.Execute();
Assert.True(stmt.AutoPage);
Assert.AreEqual(0, counter);
Assert.AreEqual(pageLength * 3, results.Count());
Assert.AreEqual(2, counter);
}