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


C# CassandraContext.OpenSession方法代码示例

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


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

示例1: CassandraDatabaseSetup

        public CassandraDatabaseSetup(bool volitile = false)
        {
            var keyspaceName = "Testing";
            var server = new Server("localhost");

            DB = new CassandraContext(keyspaceName, server);
            DB.ThrowErrors = true;

            var exists = DB.KeyspaceExists(keyspaceName);
            Users = new[] {
                new User { Id = 1, Name = "Darren Gemmell", Email = "[email protected]", Age = 32 },
                new User { Id = 2, Name = "Fernando Laubscher", Email = "[email protected]", Age = 23 },
                new User { Id = 3, Name = "Cody Millhouse", Email = "[email protected]", Age = 56 },
                new User { Id = 4, Name = "Emilia Thibert", Email = "[email protected]", Age = 67 },
                new User { Id = 5, Name = "Allyson Schurr", Email = "[email protected]", Age = 21 }
            };

            Family = DB.GetColumnFamily<AsciiType>("Standard");
            SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
            UserFamily = DB.GetColumnFamily("Users");

            if (exists && !volitile)
                return;

            using (var session = DB.OpenSession())
            {
                if (exists)
                    DB.DropKeyspace(keyspaceName);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema { Name = keyspaceName, Strategy = CassandraKeyspaceSchema.ReplicaPlacementStrategySimple, ReplicationFactor = 1 }, 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<CompositeType<LongType, UTF8Type>>("StandardCompositeType");
                keyspace.TryCreateColumnFamily<DynamicCompositeType>("StandardDynamicCompositeType");

                Family = DB.GetColumnFamily<AsciiType>("Standard");
                SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");

                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);

                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();
                UserFamily = DB.GetColumnFamily("Users");

                foreach (var user in Users)
                {
                    dynamic record = UserFamily.CreateRecord(user.Id);
                    record.Name = user.Name;
                    record.Email = user.Email;
                    record.Age = user.Age;

                    DB.Attach(record);
                }
                DB.SaveChanges();
            }
        }
开发者ID:bjuris,项目名称:fluentcassandra,代码行数:88,代码来源:CassandraDatabaseSetup.cs


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