当前位置: 首页>>代码示例>>C#>>正文


C# CassandraContext类代码示例

本文整理汇总了C#中CassandraContext的典型用法代码示例。如果您正苦于以下问题:C# CassandraContext类的具体用法?C# CassandraContext怎么用?C# CassandraContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CassandraContext类属于命名空间,在下文中一共展示了CassandraContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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();
            }
        }
开发者ID:DerekLiang,项目名称:fluentcassandra,代码行数:35,代码来源:Program.cs

示例2: CreateColumnFamilyWithTimestampOperator

        private static void CreateColumnFamilyWithTimestampOperator()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                db.ExecuteNonQuery("CREATE TABLE TestCF2 (KEY text PRIMARY KEY) WITH comparator=timestamp AND default_validation=text;");

                DateTimeOffset UnixStart = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
                DateTimeOffset TimeNow = DateTimeOffset.UtcNow;

                var columnName2 = Convert.ToInt64(Math.Floor((TimeNow - UnixStart).TotalMilliseconds));
                var columnName1 = columnName2 + 5000;

                db.ExecuteNonQuery(string.Format("INSERT INTO TestCF2 (KEY, {0}, {1}) VALUES ('Key1', 'Value1', 'Value2')", columnName1, columnName2));

                List<ICqlRow> rows = db.ExecuteQuery("SELECT * FROM TestCF2 WHERE KEY = 'Key1'").ToList();

                DateTime value1 = rows[0].Columns[1].ColumnName.GetValue<DateTime>();
                DateTime value2 = rows[0].Columns[2].ColumnName.GetValue<DateTime>();

                ConsoleHeader("Returned data from db for timestamp comparator");
                ConsoleHeader(value1.ToString());
                ConsoleHeader(value2.ToString());

            }
        }
开发者ID:nativex,项目名称:fluentcassandra,代码行数:26,代码来源:Program.cs

示例3: BigDecimalTest

        private static void BigDecimalTest()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {

                // arrange
                db.ExecuteNonQuery("CREATE TABLE OfferReservation2 (KEY text PRIMARY KEY) WITH comparator = text AND default_validation = decimal");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key0', 1000000000000000000)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key1', 0.25)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key2', 2000000000000.1234)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key3', -0.25)");
                db.ExecuteNonQuery("INSERT INTO OfferReservation2 (KEY, 'MyColumn') VALUES ('Key4', -0.25122333)");

                var actual = db.ExecuteQuery("SELECT * FROM OfferReservation2");

                var results = actual.ToList();

                var firstValue = (decimal)results.First(x => x.Key == "Key0")["MyColumn"];
                var secondValue = (decimal)results.First(x => x.Key == "Key1")["MyColumn"];
                var thirdValue = (decimal)results.First(x => x.Key == "Key2")["MyColumn"];
                var fourthValue = (decimal)results.First(x => x.Key == "Key3")["MyColumn"];
                var fifthValue = (decimal)results.First(x => x.Key == "Key4")["MyColumn"];

                ConsoleHeader("Returned data from Big Decimal Test");
                ConsoleHeader(firstValue.ToString());
                ConsoleHeader(secondValue.ToString());
                ConsoleHeader(thirdValue.ToString());
                ConsoleHeader(fourthValue.ToString());
                ConsoleHeader(fifthValue.ToString());
            }
        }
开发者ID:nativex,项目名称:fluentcassandra,代码行数:31,代码来源:Program.cs

示例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);
            }
        }
开发者ID:brooklynDev,项目名称:fluentcassandra,代码行数:35,代码来源:Program.cs

示例5: 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();

                db.ExecuteNonQuery(@"
            CREATE TABLE users (
            id int ,
            name ascii,
            email ascii,
            age int,
            PRIMARY KEY(id, email)
            );");

                ResetUsersFamily(db);
            }
        }
开发者ID:smerchek,项目名称:fluentcassandra,代码行数:28,代码来源:CassandraCql3DatabaseSetup.cs

示例6: 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();
        }
开发者ID:smerchek,项目名称:fluentcassandra,代码行数:29,代码来源:CompatibilityCassandraDatabaseSetup.cs

示例7: 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();
            }
        }
开发者ID:shawnbissell,项目名称:fluentcassandra,代码行数:35,代码来源:Program.cs

示例8: 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");
        }
开发者ID:smerchek,项目名称:fluentcassandra,代码行数:8,代码来源:LinqToCqlObjectsTests.cs

示例9: 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");
		}
开发者ID:achinn,项目名称:fluentcassandra,代码行数:8,代码来源:LinqToCqlTests.cs

示例10: LinqToCqlObjectsTests

        public LinqToCqlObjectsTests()
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            _db = new CassandraContext(keyspace: keyspaceName, server: server);
            _family = _db.GetColumnFamily<AsciiType>("Users");
        }
开发者ID:rsparkyc,项目名称:fluentcassandra,代码行数:8,代码来源:LinqToCqlObjectsTests.cs

示例11: 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 = "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(string.Format(@"
            CREATE TABLE {0} (
            id int ,
            name ascii,
            email ascii,
            age int,
            PRIMARY KEY(id)
            );", toLowerIf(toLower, "Users")));

                //db.ExecuteNonQuery(@"CREATE INDEX User_Age ON users (Age);");
                db.Keyspace.ClearCachedKeyspaceSchema();

                var family = db.GetColumnFamily<AsciiType>("Standard");
                var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
                var userFamily = db.GetColumnFamily(toLowerIf(toLower, "Users"));

                ResetFamily(family);
                ResetSuperFamily(superFamily);
                ResetUsersFamily(userFamily);
            }
        }
开发者ID:smerchek,项目名称:fluentcassandra,代码行数:57,代码来源:CompatibilityCassandraDatabaseSetup.cs

示例12: ResetDatabase

        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
            using (var db = new CassandraContext(session))
            {
                db.ThrowErrors = true;

                try { db.DropKeyspace(Keyspace); }
                catch (Exception exc) { Console.WriteLine(exc); }

                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 = "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 (
            KEY int PRIMARY KEY,
            Name ascii,
            Email ascii,
            Age int
            );");
                db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
                db.Keyspace.ClearCachedKeyspaceSchema();

                var family = db.GetColumnFamily<AsciiType>("Standard");
                var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
                var userFamily = db.GetColumnFamily("Users");

                ResetFamily(family);
                ResetSuperFamily(superFamily);
                ResetUsersFamily(userFamily);
            }
        }
开发者ID:shawnbissell,项目名称:fluentcassandra,代码行数:54,代码来源:CassandraDatabaseSetup.cs

示例13: 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("");
			});
		}
开发者ID:achinn,项目名称:fluentcassandra,代码行数:12,代码来源:ReportedIssuesTests.cs

示例14: _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);
        }
开发者ID:brooklynDev,项目名称:fluentcassandra,代码行数:48,代码来源:_CassandraSetup.cs

示例15: 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();
		}
开发者ID:juanbucz,项目名称:fluentcassandra,代码行数:16,代码来源:CassandraDatabaseSetup.cs


注:本文中的CassandraContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。