本文整理汇总了C#中CassandraContext.GetColumnFamily方法的典型用法代码示例。如果您正苦于以下问题:C# CassandraContext.GetColumnFamily方法的具体用法?C# CassandraContext.GetColumnFamily怎么用?C# CassandraContext.GetColumnFamily使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CassandraContext
的用法示例。
在下文中一共展示了CassandraContext.GetColumnFamily方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFirstPost
private static void CreateFirstPost()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
var key = "first-blog-post";
var postFamily = db.GetColumnFamily("Posts");
var tagsFamily = db.GetColumnFamily("Tags");
// create post
ConsoleHeader("create post");
dynamic post = postFamily.CreateRecord(key: key);
post.Title = "My First Cassandra Post";
post.Body = "Blah. Blah. Blah. about my first post on how great Cassandra is to work with.";
post.Author = "Nick Berardi";
post.PostedOn = DateTimeOffset.Now;
// create tags
ConsoleHeader("create post tags");
dynamic tags = tagsFamily.CreateRecord(key: key);
tags[0] = "Cassandra";
tags[1] = ".NET";
tags[2] = "Database";
tags[3] = "NoSQL";
// attach the post to the database
ConsoleHeader("attaching record");
db.Attach(post);
db.Attach(tags);
// save the changes
ConsoleHeader("saving changes");
db.SaveChanges();
}
}
示例2: CompatibilityCassandraDatabaseSetup
public CompatibilityCassandraDatabaseSetup(bool reset = false, bool toLower = false, bool toLower2 = false)
{
this.toLower = toLower;
this.toLower2 = toLower2;
ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server, cqlVersion: CqlVersion.Cql3);
DB = new CassandraContext(ConnectionBuilder);
if (DB.KeyspaceExists(Keyspace))
DB.DropKeyspace(Keyspace);
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = Keyspace,
}, DB);
var exists = DB.KeyspaceExists(Keyspace);
if(!exists)
keyspace.TryCreateSelf();
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily(toLowerIf(toLower,"Users"));
if (exists && !reset)
return;
ResetDatabase();
}
示例3: _CassandraSetup
public _CassandraSetup()
{
var keyspaceName = "Testing";
var server = new Server("localhost");
if (CassandraSession.KeyspaceExists(server, keyspaceName))
CassandraSession.DropKeyspace(server, keyspaceName);
var keyspace = new CassandraKeyspace(keyspaceName);
keyspace.TryCreateSelf(server);
keyspace.TryCreateColumnFamily<AsciiType>(server, "Standard");
keyspace.TryCreateColumnFamily<AsciiType, AsciiType>(server, "Super");
keyspace.TryCreateColumnFamily<AsciiType>(server, "StandardAsciiType");
keyspace.TryCreateColumnFamily<BytesType>(server, "StandardBytesType");
keyspace.TryCreateColumnFamily<IntegerType>(server, "StandardIntegerType");
keyspace.TryCreateColumnFamily<LexicalUUIDType>(server, "StandardLexicalUUIDType");
keyspace.TryCreateColumnFamily<LongType>(server, "StandardLongType");
keyspace.TryCreateColumnFamily<TimeUUIDType>(server, "StandardTimeUUIDType");
keyspace.TryCreateColumnFamily<UTF8Type>(server, "StandardUTF8Type");
keyspace.TryCreateColumnFamily<UUIDType>(server, "StandardUUIDType");
keyspace.TryCreateColumnFamily<CompositeType<LongType, UTF8Type>>(server, "StandardCompositeType");
keyspace.TryCreateColumnFamily<DynamicCompositeType>(server, "StandardDynamicCompositeType");
DB = new CassandraContext(keyspaceName, server);
DB.ThrowErrors = true;
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
Family.RemoveAllRows();
SuperFamily.RemoveAllRows();
Family.InsertColumn(TestKey1, "Test1", Math.PI);
Family.InsertColumn(TestKey1, "Test2", Math.PI);
Family.InsertColumn(TestKey1, "Test3", Math.PI);
SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test1", Math.PI);
SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test2", Math.PI);
SuperFamily.InsertColumn(TestKey1, TestSuperName, "Test3", Math.PI);
Family.InsertColumn(TestKey2, "Test1", Math.PI);
Family.InsertColumn(TestKey2, "Test2", Math.PI);
Family.InsertColumn(TestKey2, "Test3", Math.PI);
SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test1", Math.PI);
SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test2", Math.PI);
SuperFamily.InsertColumn(TestKey2, TestSuperName, "Test3", Math.PI);
}
示例4: DoWork
private static void DoWork()
{
using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
{
Stopwatch watch = new Stopwatch();
watch.Start();
Random random = new Random();
byte[] data = new byte[dataLength];
random.NextBytes(data);
int errors = 0;
for (int i = 0; i < count; i++)
{
// Insert
Guid postId = Guid.NewGuid();
string titleName = i.ToString();
var family = db.GetColumnFamily<UTF8Type, UTF8Type>("Posts");
dynamic post = family.CreateRecord(postId);
dynamic details = post.CreateSuperColumn();
details.Body = data;
post[DateTime.Now] = details;
db.Attach(post);
db.SaveChanges();
}
double rate = count / watch.Elapsed.TotalSeconds;
double throughput = rate * data.Length;
Console.WriteLine("Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput + "\tErrors:" + errors);
}
}
示例5: CreateComments
private static void CreateComments()
{
using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
{
var key = "first-blog-post";
// get the comments family
var commentsFamily = db.GetColumnFamily<TimeUUIDType, UTF8Type>("Comments");
ConsoleHeader("create comments");
dynamic postComments = commentsFamily.CreateRecord(key: key);
// lets attach it to the database before we add the comments
db.Attach(postComments);
// add 5 comments
for (int i = 0; i < 5; i++)
{
dynamic comment = postComments.CreateSuperColumn();
comment.Name = "Nick Berardi";
comment.Email = "[email protected]";
comment.Website = "www.coderjournal.com";
comment.Comment = "Wow fluent cassandra is really great and easy to use.";
var commentPostedOn = DateTime.Now;
postComments[commentPostedOn] = comment;
Console.WriteLine("Comment " + (i + 1) + " Posted On " + commentPostedOn.ToLongTimeString());
Thread.Sleep(TimeSpan.FromSeconds(2));
}
// save the comments
db.SaveChanges();
}
}
示例6: CassandraDatabaseSetup
public CassandraDatabaseSetup(bool reset = false)
{
ConnectionBuilder = new ConnectionBuilder(keyspace: Keyspace, server: Server);
DB = new CassandraContext(ConnectionBuilder);
var exists = DB.KeyspaceExists(Keyspace);
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily("Users");
if (exists && !reset)
return;
ResetDatabase();
}
示例7: LinqToCqlObjectsTests
public LinqToCqlObjectsTests()
{
var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
_db = new CassandraContext(keyspace: keyspaceName, server: server);
_family = _db.GetColumnFamily<AsciiType>("Users");
}
示例8: LinqToCqlTests
public LinqToCqlTests()
{
var keyspaceName = ConfigurationManager.AppSettings["TestKeySpace"];
var server = new Server(ConfigurationManager.AppSettings["TestServer"]);
_db = new CassandraContext(new ConnectionBuilder(keyspace: keyspaceName, server: server, cqlVersion: CqlVersion.Cql));
_family = _db.GetColumnFamily<AsciiType>("Users");
}
示例9: LinqToCqlObjectsTests
public LinqToCqlObjectsTests()
{
var keyspaceName = "Testing";
var server = new Server("localhost");
_db = new CassandraContext(keyspace: keyspaceName, server: server);
_family = _db.GetColumnFamily<AsciiType>("Users");
}
示例10: CreateRecord_Doesnt_Check_BytesType_Zero_Length
public void CreateRecord_Doesnt_Check_BytesType_Zero_Length()
{
// arrange
var db = new CassandraContext("Test1", "localhost");
var family = db.GetColumnFamily<AsciiType>(FamilyName);
// act
// assert
Assert.Throws<ArgumentException>(delegate {
dynamic value = family.CreateRecord("");
});
}
示例11: Init
public void Init()
{
_context = new CassandraContext(keyspace: DummiesKeySpace, host: "localhost");
if (!_context.KeyspaceExists(DummiesKeySpace))
{
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
{
Name = DummiesKeySpace,
}, _context);
keyspace.TryCreateSelf();
_context.ExecuteQuery(
@"
CREATE COLUMNFAMILY Dummies (
KEY ascii PRIMARY KEY,
Blob blob
);");
_context.SaveChanges();
}
_dummies = _context.GetColumnFamily("Dummies");
}
示例12: ResetDatabase
public void ResetDatabase()
{
using (var session = new CassandraSession(ConnectionBuilder))
using (var db = new CassandraContext(session))
{
db.ThrowErrors = true;
db.TryDropKeyspace(Keyspace);
var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
Name = Keyspace
}, db);
db.Keyspace = keyspace;
keyspace.TryCreateSelf();
keyspace.TryCreateColumnFamily<AsciiType>("Standard");
keyspace.TryCreateColumnFamily<AsciiType, AsciiType>("Super");
keyspace.TryCreateColumnFamily<AsciiType>("StandardAsciiType");
keyspace.TryCreateColumnFamily<BytesType>("StandardBytesType");
keyspace.TryCreateColumnFamily<IntegerType>("StandardIntegerType");
keyspace.TryCreateColumnFamily<LexicalUUIDType>("StandardLexicalUUIDType");
keyspace.TryCreateColumnFamily<LongType>("StandardLongType");
keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema() {
FamilyName = "Counters",
ColumnNameType = CassandraType.AsciiType,
DefaultColumnValueType = CassandraType.CounterColumnType
});
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardDecimalType",
ColumnNameType = CassandraType.DecimalType
});
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardCompositeType",
ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
});
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardDynamicCompositeType",
ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
});
db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
Id int PRIMARY KEY,
Name ascii,
Email ascii,
Age int
);", CqlVersion.Cql);
db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);", CqlVersion.Cql);
db.Keyspace.ClearCachedKeyspaceSchema();
var family = db.GetColumnFamily<AsciiType>("Standard");
var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
var userFamily = db.GetColumnFamily("Users");
var counterFamily = db.GetColumnFamily("Counters");
ResetFamily(family);
ResetSuperFamily(superFamily);
ResetUsersFamily(userFamily);
ResetCounterColumnFamily(counterFamily);
}
}
示例13: UpdateFirstPost
private static void UpdateFirstPost()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
var key = "first-blog-post";
var postFamily = db.GetColumnFamily("Posts");
// get the post back from the database
ConsoleHeader("getting 'first-blog-post' for update");
// query using API
dynamic post = postFamily.Get(key).FirstOrDefault();
post.Title = post.Title + "(updated)";
post.Body = post.Body + "(updated)";
post.Author = post.Author + "(updated)";
post.PostedOn = DateTimeOffset.Now;
// attach the post to the database
ConsoleHeader("attaching record");
db.Attach(post);
// save the changes
ConsoleHeader("saving changes");
db.SaveChanges();
}
}
示例14: ReadFirstPost
private static void ReadFirstPost()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
var key = "first-blog-post";
var postFamily = db.GetColumnFamily("Posts");
var tagsFamily = db.GetColumnFamily("Tags");
// get the post back from the database
ConsoleHeader("getting 'first-blog-post'");
// query using API
dynamic post = postFamily.Get(key).FirstOrDefault();
// query using CQL-LINQ
dynamic tags = (
from t in tagsFamily
where t.Key == key
select t).FirstOrDefault();
// show details
ConsoleHeader("showing post");
Console.WriteLine(
String.Format("=={0} by {1}==\n{2}",
post.Title,
post.Author,
post.Body
));
// show tags
ConsoleHeader("showing tags");
foreach (var tag in tags)
Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
}
}
示例15: ReadAllPosts
private static void ReadAllPosts()
{
using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
{
var key = "first-blog-post";
var tagsFamily = db.GetColumnFamily("Tags");
// get the post back from the database
ConsoleHeader("getting 'first-blog-post'");
// query using CQL
var posts = db.ExecuteQuery("SELECT * FROM Posts LIMIT 25");
// query using API
dynamic tags = tagsFamily.Get(key).FirstOrDefault();
// show details
ConsoleHeader("showing post");
foreach (dynamic post in posts)
{
Console.WriteLine(
String.Format("=={0} by {1}==\n{2}",
post.Title,
post.Author,
post.Body
));
}
// show tags
ConsoleHeader("showing tags");
foreach (var tag in tags)
Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
}
}