本文整理汇总了C#中Table.GetSession方法的典型用法代码示例。如果您正苦于以下问题:C# Table.GetSession方法的具体用法?C# Table.GetSession怎么用?C# Table.GetSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.GetSession方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteReadValidateUsingSessionBatch
private static AllDataTypesEntity WriteReadValidateUsingSessionBatch(Table<AllDataTypesEntity> table)
{
Batch batch = table.GetSession().CreateBatch();
AllDataTypesEntity expectedDataTypesEntityRow = AllDataTypesEntity.GetRandomInstance();
string uniqueKey = expectedDataTypesEntityRow.StringType;
batch.Append(table.Insert(expectedDataTypesEntityRow));
batch.Execute();
List<AllDataTypesEntity> listOfAllDataTypesObjects = (from x in table where x.StringType.Equals(uniqueKey) select x).Execute().ToList();
Assert.NotNull(listOfAllDataTypesObjects);
Assert.AreEqual(1, listOfAllDataTypesObjects.Count);
AllDataTypesEntity actualDataTypesEntityRow = listOfAllDataTypesObjects.First();
expectedDataTypesEntityRow.AssertEquals(actualDataTypesEntityRow);
return expectedDataTypesEntityRow;
}
示例2: 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);
}
示例3: WriteReadValidateUsingTableMethods
private static AllDataTypesEntity WriteReadValidateUsingTableMethods(Table<AllDataTypesEntity> table)
{
AllDataTypesEntity expectedDataTypesEntityRow = AllDataTypesEntity.GetRandomInstance();
string uniqueKey = expectedDataTypesEntityRow.StringType;
// insert record
table.GetSession().Execute(table.Insert(expectedDataTypesEntityRow));
// select record
List<AllDataTypesEntity> listOfAllDataTypesObjects = (from x in table where x.StringType.Equals(uniqueKey) select x).Execute().ToList();
Assert.NotNull(listOfAllDataTypesObjects);
Assert.AreEqual(1, listOfAllDataTypesObjects.Count);
AllDataTypesEntity actualDataTypesEntityRow = listOfAllDataTypesObjects.First();
expectedDataTypesEntityRow.AssertEquals(actualDataTypesEntityRow);
return expectedDataTypesEntityRow;
}