Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have this problem with using Fluent Cassandra in a test application. All I want to do is set the IsOnline field to true inside the SignIn method, but I keep getting the exception supercolumn parameter is not optional for super CF. I've tried many things, but haven't been able to get it to work. All the data is created and inserted into my Cassandra Keyspace, but to change it again to IsOnline after insertion is failing me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FluentCassandra;
using FluentCassandra.Connections;
using FluentCassandra.Types;
using FluentCassandra.Operations;
using FluentCassandra.ObjectSerializer;
using FluentCassandra.Linq;

namespace CassandraTryTwo
{
    class Program
    {
        private static void CreateDatabase()
        {
            using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
            {
                if (context.KeyspaceExists("RadiumNet"))
                {
                    context.DropKeyspace("RadiumNet");
                }

                var keyspace = new CassandraKeyspace("RadiumNet", context);

                keyspace.TryCreateSelf();
                keyspace.TryCreateColumnFamily(
                    new CassandraColumnFamilySchema
                    {
                        FamilyName = "Accounts",
                        FamilyType = ColumnType.Super,
                        KeyValueType = CassandraType.UTF8Type,
                        SuperColumnNameType = CassandraType.UTF8Type,
                        ColumnNameType = CassandraType.UTF8Type,
                        DefaultColumnValueType = CassandraType.UTF8Type
                    }
                );
            }

            return;
        }

        private static void SignUp(String email, String password, String name, String surname, String age)
        {
            using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
            {
                var accountFamily = context.GetSuperColumnFamily("Accounts");
                var accountColumn = accountFamily.Get(email).First();

                if (accountColumn.Count() > 0)
                {
                    Console.WriteLine("User {0} already registered", email);
                }
                else
                {
                    dynamic account = accountColumn;

                    account = accountFamily.CreateRecord(key: email);

                    dynamic details = account.CreateSuperColumn();
                    details.Password = password;
                    details.Name = name;
                    details.Surname = surname;
                    details.Age = age;

                    dynamic flags = account.CreateSuperColumn();
                    flags.IsBlocked = "False";
                    flags.IsBanned = "False";
                    flags.IsOnline = "False";

                    account.Details = details;
                    account.Flags = flags;

                    context.Attach(account);
                    context.SaveChanges();
                }
            }

            return;
        }

        private static void SignIn(String email, String password)
        {
            using (var context = new CassandraContext(keyspace: "RadiumNet", host: "localhost"))
            {
                var accountFamily = context.GetSuperColumnFamily("Accounts");
                var accountColumn = accountFamily.Get(email).First();

                if (accountColumn.Count() == 0)
                {
                    Console.WriteLine("User {0} did not register", email);
                }
                else
                {
                    dynamic account = accountColumn;
                    dynamic details = account.Details;
                    dynamic flags = account.Flags;

                    if (details.Password != password)
                    {
                        Console.WriteLine("User {0} provided an invalid password", email);
                    }
                    else
                    {
                        flags.IsOnline = "True";

                        Console.WriteLine("Welcome {0} {1}", details.Name, details.Surname);

                        context.Attach(account);
                        context.SaveChanges();
                    }
                }
            }

            return;
        }

        private static void SetupConsole()
        {
            Console.Title = "Cassandra Test";
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;

            Console.SetWindowSize(120, 40);
            Console.Clear();
        }

        private static void Pause()
        {
            Console.WriteLine();
            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
        }

        private static void Main(string[] args)
        {
            SetupConsole();

            CreateDatabase();

            SignUp("foo@bar.com", "BooBab", "Wynand", "Pieterse", "22");
            SignUp("gee@wiz.com", "GreenBab", "Henk", "Pieterse", "27");

            SignIn("foo@bar.com", "BooBab");
            SignIn("bla@gmail.com", "Grrr");
            SignIn("gee@wiz.com", "Breezer");

            Pause();
        }
    }
}
share|improve this question
    
is the Accounts CF defined as a SuperCF? And which line (exactly) is the exception being thrown on? –  BryceAtNetwork23 Aug 25 '12 at 13:56
    
Yes accounts is a SuperCF, and the error happens at the place where I call context.SaveChanges() function. I've tried the Attach function on top of the SaveChanges function, but it did not help, I also tried disconnecting the entity and reattaching it, but also, the same error keeps on happening –  MrWiggels Aug 25 '12 at 19:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.