本文整理汇总了C#中Table.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Insert方法的具体用法?C# Table.Insert怎么用?C# Table.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert_Com_Valor_Nulo
public void Insert_Com_Valor_Nulo()
{
var users = new Table("users");
users.Insert(new { nome="george", idade=Utils.NULL });
string sql_expected = "INSERT INTO users(idade, nome) VALUES(NULL, @users_nome_1)";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例2: LinqInsert_Batch_Test
public void LinqInsert_Batch_Test()
{
Table<Movie> nerdMoviesTable = new Table<Movie>(_session, new MappingConfiguration());
Batch batch = _session.CreateBatch();
Movie movie1 = Movie.GetRandomMovie();
Movie movie2 = Movie.GetRandomMovie();
movie1.Director = "Joss Whedon";
var movies = new List<Movie>
{
movie1,
movie2,
};
batch.Append(from m in movies select nerdMoviesTable.Insert(m));
Task taskSaveMovies = Task.Factory.FromAsync(batch.BeginExecute, batch.EndExecute, null);
taskSaveMovies.Wait();
Task taskSelectStartMovies = Task<IEnumerable<Movie>>.Factory.FromAsync(
nerdMoviesTable.BeginExecute, nerdMoviesTable.EndExecute, null).
ContinueWith(res => Movie.DisplayMovies(res.Result));
taskSelectStartMovies.Wait();
CqlQuery<Movie> selectAllFromWhere = from m in nerdMoviesTable where m.Director == movie1.Director select m;
Task taskselectAllFromWhere =
Task<IEnumerable<Movie>>.Factory.FromAsync(selectAllFromWhere.BeginExecute, selectAllFromWhere.EndExecute, null).
ContinueWith(res => Movie.DisplayMovies(res.Result));
taskselectAllFromWhere.Wait();
Task<List<Movie>> taskselectAllFromWhereWithFuture = Task<IEnumerable<Movie>>.
Factory.FromAsync(selectAllFromWhere.BeginExecute, selectAllFromWhere.EndExecute, null).
ContinueWith(a => a.Result.ToList());
Movie.DisplayMovies(taskselectAllFromWhereWithFuture.Result);
}
示例3: Insert_Simples
public void Insert_Simples()
{
ITable users = new Table("users");
users.Insert(new { nome = "george", data_nascimento = new DateTime(1989, 8, 22), sexo = "M" });
string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) "+
"VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
Assert.AreEqual(sql_expected, users.ToSql());
}
示例4: InsertIfNotPresentTest
public void InsertIfNotPresentTest ()
{
Table<int, string> table = new Table<int, string> ();
table.Insert (1, "one", false);
table.InsertIfNotPresent (1, "two");
Assert.AreEqual ("one", table.Lookup (1), "B1");
}
示例5: InsertTest
public void InsertTest ()
{
Table<int, string> table = new Table<int, string> ();
table.Insert (1, "one", false);
table.Insert (2, "two", false);
table.Insert (3, "three", false);
Assert.AreEqual ("one", table.Lookup (1), "A1");
Assert.AreEqual ("two", table.Lookup (2), "A2");
Assert.AreEqual ("three", table.Lookup (3), "A3");
Assert.AreEqual (null, table.Lookup (4), "A4");
table.Insert (1, "four", true);
table.Insert (1, "one", false);
Assert.AreEqual ("four", table.Lookup (1), "A5");
}
示例6: LinqInsert_WithSetTimestamp_Test
public void LinqInsert_WithSetTimestamp_Test()
{
Table<Movie> nerdMoviesTable = new Table<Movie>(_session, new MappingConfiguration());
Movie movie1 = Movie.GetRandomMovie();
nerdMoviesTable.Insert(movie1).Execute();
string mainActor = "Samuel L. Jackson";
movie1.MainActor = mainActor;
nerdMoviesTable
.Insert(movie1)
.SetTimestamp(DateTime.Now.AddDays(1))
.Execute();
Movie updatedMovie = nerdMoviesTable
.Where(m => m.Title == movie1.Title && m.MovieMaker == movie1.MovieMaker)
.Execute()
.First();
Assert.AreEqual(updatedMovie.MainActor, mainActor);
}
示例7: Insert_Usando_Hashtable
public void Insert_Usando_Hashtable()
{
Hashtable hs = new Hashtable();
hs.Add("nome", "george");
hs.Add("data_nascimento", new DateTime(1989, 8, 22));
hs.Add("sexo", "M");
var t_users = new Table("users");
t_users.Insert(hs);
Console.WriteLine(t_users.ToSql());
string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) "
+"VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
Assert.AreEqual(sql_expected, t_users.ToSql());
}
示例8: SetupDefaultTable
public static Tuple<Table<EntityWithAllCollectionTypes>, List<EntityWithAllCollectionTypes>> SetupDefaultTable(ISession session)
{
// create table
var config = new MappingConfiguration().Define(
new Map<EntityWithAllCollectionTypes>()
.TableName("EntityWithAllCollectionTypes_" + Randomm.RandomAlphaNum(12))
.PartitionKey(u => u.Id));
Table<EntityWithAllCollectionTypes> table = new Table<EntityWithAllCollectionTypes>(session, config);
table.Create();
List<EntityWithAllCollectionTypes> entityList = GetDefaultAllDataTypesList();
//Insert some data
foreach (var singleEntity in entityList)
table.Insert(singleEntity).Execute();
return new Tuple<Table<EntityWithAllCollectionTypes>, List<EntityWithAllCollectionTypes>>(table, entityList);
}
示例9: 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();
}
示例10: SetupTest
public void SetupTest()
{
_session = TestClusterManager.GetTestCluster(1).Session;
_session.CreateKeyspace(_uniqueKsName);
_session.ChangeKeyspace(_uniqueKsName);
// drop table if exists, re-create
var config = new Map<Movie>().PartitionKey(c => c.MovieMaker);
var mappingConfig = new MappingConfiguration().Define(config);
_mapper = new Mapper(_session, mappingConfig);
_movieTable = new Table<Movie>(_session, mappingConfig);
_movieTable.Create();
//Insert some data
foreach (var movie in _movieList)
_movieTable.Insert(movie).Execute();
}
示例11: TestFixtureSetUp
protected override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
_session = 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();
}
示例12: TestFixtureSetUp
protected override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
_session = Session;
_session.CreateKeyspace(_uniqueKsName);
_session.ChangeKeyspace(_uniqueKsName);
// drop table if exists, re-create
var config = new Map<Movie>().PartitionKey(c => c.MovieMaker);
var mappingConfig = new MappingConfiguration().Define(config);
_mapper = new Mapper(_session, mappingConfig);
_movieTable = new Table<Movie>(_session, mappingConfig);
_movieTable.Create();
//Insert some data
foreach (var movie in _movieList)
_movieTable.Insert(movie).Execute();
}
示例13: 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);
}
示例14: 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");
}
示例15: LinqInsert_IfNotExists_Test
public void LinqInsert_IfNotExists_Test()
{
var nerdMoviesTable = new Table<Movie>(_session, new MappingConfiguration());
var movie = Movie.GetRandomMovie();
var appliedInfo = nerdMoviesTable.
Insert(movie)
.IfNotExists()
.Execute();
Assert.True(appliedInfo.Applied);
Assert.Null(appliedInfo.Existing);
Assert.NotNull(nerdMoviesTable
.Where(m => m.Title == movie.Title && m.MovieMaker == movie.MovieMaker)
.Execute()
.FirstOrDefault());
//Try to create another with the same partition and clustering keys
appliedInfo = nerdMoviesTable
.Insert(new Movie { Title = movie.Title, Director = movie.Director, MovieMaker = movie.MovieMaker})
.IfNotExists()
.Execute();
Assert.False(appliedInfo.Applied);
Assert.NotNull(appliedInfo.Existing);
Assert.AreEqual(movie.Year, appliedInfo.Existing.Year);
}