Convert Methods

CassandraEntity Class

CassandraEntity has some powerful converter method. They convert "Column, SuperColumn, CounterColumn, CounterSuperColumn, List<Column>, List<SuperColumn>, List<CounterColumn>, List<CounterSuperColumn>" to "object, List, Dictionary".
  • ToObject<TOutput> ()
  • ToObjectList<TOutputItem> ()
  • ToFlatNameList<TOutputItem> ()
  • ToFlatValueList<TOutputItem> ()
  • ToObjectDictionary<TOutputKey, TOutputValue> ()
  • ToFlatDictionary<TOutputKey, TOutputValue> ()
  • ToFlatValueKeyDictionary<TOutputKey, TOutputValue> ()
  • ToNameListDictionary<TOutputKey, TListItem> ()
  • ToValueListDictionary<TOutputKey, TListItem> ()
  • ToDictionaryDictionary<TOutputKey, TDictionaryKey, TDictionaryValue> ()
  • ToValueKeyDictionaryDictionary<TOutputKey, TDictionaryKey, TDictionaryValue> ()
Cassandraemon uses its own serialization mechanism to convert rows to objects and vice versa. See Serializations topic for further information.

CqlResult Class

CqlResult has some powerful converter method, too. Behavior of these methods are same as CassandraEntity<List<Column>>.
  • ToCassandraEntiry ()
  • ToFlatNameList<T> ()
  • ToFlatValueList<T> ()
  • ToFlatDictionary<TKey, TValue> ()
  • ToFlatValueKeyDictionary<TKey, TValue> ()
  • ToNameListDictionary<TKey, TListItem> ()
  • ToValueListDictionary<TKey, TListItem> ()
  • ToObjectList<T> ()
  • ToObjectDictionary<TKey, TValue> ()



Convert Column

/****************************/
/********* Ready **********/
/****************************/

/* Test ColumnFamily
"Key1"
{
	"Name1" : 1
}
*/

var entitys = from x in context.Column
	      where x.Key == "Key1" &&
	            x.ColumnFamily == "Test" &&
	            x.Column == "Name1".ToCassandraByte()
	      select x;

CassandraEntity<Column> entity = entitys.ToList()[0];

class Test
{
	public int Name1 { get; set; }
}


/*******************************/
/********* Convert ! **********/
/*******************************/

Test toObject = entity.ToObject<Test>();
/*
new Test { Name1 = 1 };
*/


List<Test> toObjectList = entity.ToObjectList<Test>();
/*
new List<Test> {  new Test { Name1 = 1 } };
*/


List<string> toFlatNameList = entity.ToFlatNameList<string>();
/*
new List<string> { "Name1" };
*/


List<int> toFlatValueList = entity.ToFlatValueList<int>();
/*
new List<int> { 1 };
*/


Dictionary<int, Test> toObjectDictionary = entity.ToObjectDictionary<int, Test>();
/*
new Dictionary<int, Test> 
{ 
	{ default(int), new Test { Name1 = 1 } } 
};
*/


Dictionary<string, int> toFlatDictionary = entity.ToFlatDictionary<string, int>();
/*
new Dictionary<string, int> 
{ 
	{ "Name1", 1 } 
};
*/


Dictionary<int, string> toFlatValueKeyDictionary = entity.ToFlatValueKeyDictionary<int, string>();
/*
new Dictionary<int, string> 
{ 
	{ 1, "Name1" } 
};
*/


Dictionary<int, List<string>> toNameListDictionary = entity.ToNameListDictionary<int, string>();
/*
new Dictionary<int, List<string>> 
{ 
	{ default(int), new List<string> { "Name1" } } 
};
*/


Dictionary<int, List<int>> toValueListDictionary = entity.ToValueListDictionary<int, int>();
/*
new Dictionary<int, List<int>> 
{ 
	{ default(int), new List<int> { 1 } } 
};
*/


Dictionary<int, Dictionary<string, int>> toDictionaryDictionary = entity.ToDictionaryDictionary<int, string, int>();
/*
new Dictionary<int, Dictionary<string, int>> 
{ 
	{ default(int), new Dictionary<string, int> { { "Name1", 1 } } } 
};
*/


Dictionary<int, Dictionary<int, string>> toValueKeyDictionaryDictionary = entity.ToValueKeyDictionaryDictionary<int, int, string>();
/*
new Dictionary<int, Dictionary<int, string>> 
{ 
	{ default(int), new Dictionary<int, string> { { 1, "Name1" } } } 
};
*/



Convert SuperColumn

/****************************/
/********* Ready **********/
/****************************/

/* Test ColumnFamily
"Key1"
{
	"SCName1"
	{
		"Name1" : 1,
		"Name2" : 2,
		"Name3" : 3
	}
}
*/

var entitys = from x in context.SuperColumn
	      where x.Key == "Key1" &&
	            x.ColumnFamily == "Test" &&
	            x.SuperColumn == "SCName1".ToCassandraByte()
	      select x;

CassandraEntity<SuperColumn> entity = entitys.ToList()[0];

class Test
{
	public int Name1 { get; set; }
	public int Name2 { get; set; }
	public int Name3 { get; set; }
}


/*******************************/
/********* Convert ! **********/
/*******************************/

Test toObject = entity.ToObject<Test>();
/*
new Test 
{ 
	Name1 = 1,
	Name2 = 2,
	Name3 = 3
 };
*/


List<Test> toObjectList = entity.ToObjectList<Test>();
/*
new List<Test> 
{  
	new Test 
	{ 
		Name1 = 1, 
		Name2 = 2, 
		Name3 = 3
	} 
};
*/


List<string> toFlatNameList = entity.ToFlatNameList<string>();
/*
new List<string> { "Name1", "Name2", "Name3" };
*/


List<int> toFlatValueList = entity.ToFlatValueList<int>();
/*
new List<int> { 1, 2, 3 };
*/


Dictionary<string, Test> toObjectDictionary = entity.ToObjectDictionary<string, Test>();
/*
new Dictionary<string, Test> 
{ 
	{ 
		"SCName1", 
		new Test 
		{ 
			Name1 = 1,
			Name2 = 2,
			Name3 = 3
		} 
	} 
};
*/


Dictionary<string, int> toFlatDictionary = entity.ToFlatDictionary<string, int>();
/*
new Dictionary<string, int> 
{ 
	{ "Name1", 1 },
	{ "Name2", 2 },
	{ "Name3", 3 }
};
*/


Dictionary<int, string> toFlatValueKeyDictionary = entity.ToFlatValueKeyDictionary<int, string>();
/*
new Dictionary<int, string> 
{ 
	{ 1, "Name1" },
	{ 2, "Name2" },
	{ 3, "Name3" }
};
*/


Dictionary<string, List<string>> toNameListDictionary = entity.ToNameListDictionary<string, string>();
/*
new Dictionary<string, List<string>> 
{ 
	{ "SCName1", new List<string> { "Name1", "Name2", "Name3" } } 
};
*/


Dictionary<string, List<int>> toValueListDictionary = entity.ToValueListDictionary<string, int>();
/*
new Dictionary<string, List<int>> 
{ 
	{ "SCName1", new List<int> { 1, 2, 3 } } 
};
*/


Dictionary<string, Dictionary<string, int>> toDictionaryDictionary = entity.ToDictionaryDictionary<string, string, int>();
/*
new Dictionary<string, Dictionary<string, int>> 
{ 
	{ 
		"SCName1", 
		new Dictionary<string, int> 
		{ 
			{ "Name1", 1 },
			{ "Name2", 2 },
			{ "Name3", 3 }
		} 
	} 
};
*/


Dictionary<string, Dictionary<int, string>> toValueKeyDictionaryDictionary = entity.ToValueKeyDictionaryDictionary<string, int, string>();
/*
new Dictionary<string, Dictionary<int, string>> 
{ 
	{ 
		"SCName1", 
		new Dictionary<int, string> 
		{ 
			{ 1, "Name1" },
			{ 2, "Name2" },
			{ 3, "Name3" }
		} 
	} 
};
*/



Convert ColumnList

/****************************/
/********* Ready **********/
/****************************/

/* Test ColumnFamily
"Key1"
{
	"Name1" : 1,
	"Name2" : 2,
	"Name3" : 3
}
*/

var entitys = from x in context.ColumnList
	      where x.Key == "Key1" &&
	            x.ColumnFamily == "Test"
	      select x;

CassandraEntity<List<Column>> entity = entitys.ToList()[0];

class Test
{
	public int Name1 { get; set; }
	public int Name2 { get; set; }
	public int Name3 { get; set; }
}


/*******************************/
/********* Convert ! **********/
/*******************************/

Test toObject = entity.ToObject<Test>();
/*
new Test 
{ 
	Name1 = 1,
	Name2 = 2,
	Name3 = 3
 };
*/


List<Test> toObjectList = entity.ToObjectList<Test>();
/*
new List<Test> 
{  
	new Test 
	{ 
		Name1 = 1, 
		Name2 = 2, 
		Name3 = 3
	} 
};
*/


List<string> toFlatNameList = entity.ToFlatNameList<string>();
/*
new List<string> { "Name1", "Name2", "Name3" };
*/


List<int> toFlatValueList = entity.ToFlatValueList<int>();
/*
new List<int> { 1, 2, 3 };
*/


Dictionary<int, Test> toObjectDictionary = entity.ToObjectDictionary<int, Test>();
/*
new Dictionary<int, Test> 
{ 
	{ 
		default(int), 
		new Test 
		{ 
			Name1 = 1,
			Name2 = 2,
			Name3 = 3
		} 
	} 
};
*/


Dictionary<string, int> toFlatDictionary = entity.ToFlatDictionary<string, int>();
/*
new Dictionary<string, int> 
{ 
	{ "Name1", 1 },
	{ "Name2", 2 },
	{ "Name3", 3 }
};
*/


Dictionary<int, string> toFlatValueKeyDictionary = entity.ToFlatValueKeyDictionary<int, string>();
/*
new Dictionary<int, string> 
{ 
	{ 1, "Name1" },
	{ 2, "Name2" },
	{ 3, "Name3" }
};
*/


Dictionary<int, List<string>> toNameListDictionary = entity.ToNameListDictionary<int, string>();
/*
new Dictionary<int, List<string>> 
{ 
	{ default(int), new List<string> { "Name1", "Name2", "Name3" } } 
};
*/


Dictionary<int, List<int>> toValueListDictionary = entity.ToValueListDictionary<int, int>();
/*
new Dictionary<int, List<int>> 
{ 
	{ default(int), new List<int> { 1, 2, 3 } } 
};
*/


Dictionary<int, Dictionary<string, int>> toDictionaryDictionary = entity.ToDictionaryDictionary<int, string, int>();
/*
new Dictionary<int, Dictionary<string, int>> 
{ 
	{ 
		default(int), 
		new Dictionary<string, int> 
		{ 
			{ "Name1", 1 },
			{ "Name2", 2 },
			{ "Name3", 3 }
		} 
	} 
};
*/


Dictionary<int, Dictionary<int, string>> toValueKeyDictionaryDictionary = entity.ToValueKeyDictionaryDictionary<int, int, string>();
/*
new Dictionary<int, Dictionary<int, string>> 
{ 
	{ 
		default(int), 
		new Dictionary<int, string> 
		{ 
			{ 1, "Name1" },
			{ 2, "Name2" },
			{ 3, "Name3" }
		} 
	} 
};
*/



Convert SuperColumnList

/****************************/
/********* Ready **********/
/****************************/

/* Test ColumnFamily
"Key1"
{
	"SCName1"
	{
		"Name1" : 1,
		"Name2" : 2,
		"Name3" : 3
	},
	"SCName2"
	{
		"Name1" : 4,
		"Name2" : 5,
		"Name3" : 6
	},
	"SCName3"
	{
		"Name1" : 7,
		"Name2" : 8,
		"Name3" : 9
	}
}
*/

var entitys = from x in context.SuperColumnList
	      where x.Key == "Key1" &&
	            x.ColumnFamily == "Test"
	      select x;

CassandraEntity<List<SuperColumn>> entity = entitys.ToList()[0];

class Test
{
	public int Name1 { get; set; }
	public int Name2 { get; set; }
	public int Name3 { get; set; }
}


/*******************************/
/********* Convert ! **********/
/*******************************/

Test toObject = entity.ToObject<Test>();
/*
new Test 
{ 
	Name1 = 1,
	Name2 = 2,
	Name3 = 3
};
*/


List<Test> toObjectList = entity.ToObjectList<Test>();
/*
new List<Test> 
{  
	new Test 
	{ 
		Name1 = 1, 
		Name2 = 2, 
		Name3 = 3
	},
	new Test 
	{ 
		Name1 = 4, 
		Name2 = 5, 
		Name3 = 6
	},
	new Test 
	{ 
		Name1 = 7, 
		Name2 = 8, 
		Name3 = 9
	} 
};
*/


List<string> toFlatNameList = entity.ToFlatNameList<string>();
/*
new List<string> 
{ 
	"Name1", "Name2", "Name3",
	"Name1", "Name2", "Name3",
	"Name1", "Name2", "Name3"
};
*/


List<int> toFlatValueList = entity.ToFlatValueList<int>();
/*
new List<int> 
{ 
	1, 2, 3,
	4, 5, 6,
	7, 8, 9
};
*/


Dictionary<string, Test> toObjectDictionary = entity.ToObjectDictionary<string, Test>();
/*
new Dictionary<string, Test> 
{ 
	{ 
		"SCName1", 
		new Test 
		{ 
			Name1 = 1,
			Name2 = 2,
			Name3 = 3
		} 
	},
	{ 
		"SCName2", 
		new Test 
		{ 
			Name1 = 4,
			Name2 = 5,
			Name3 = 6
		} 
	},
	{ 
		"SCName3", 
		new Test 
		{ 
			Name1 = 7,
			Name2 = 8,
			Name3 = 9
		} 
	} 
};
*/


Dictionary<string, int> toFlatDictionary = entity.ToFlatDictionary<string, int>();
/*
new Dictionary<string, int> 
{ 
	{ "Name1", 1 },
	{ "Name2", 2 },
	{ "Name3", 3 },
	{ "Name1", 4 },
	{ "Name2", 5 },
	{ "Name3", 6 },
	{ "Name1", 7 },
	{ "Name2", 8 },
	{ "Name3", 9 }
};
*/


Dictionary<int, string> toFlatValueKeyDictionary = entity.ToFlatValueKeyDictionary<int, string>();
/*
new Dictionary<int, string> 
{ 
	{ 1, "Name1" },
	{ 2, "Name2" },
	{ 3, "Name3" },
	{ 4, "Name1" },
	{ 5, "Name2" },
	{ 6, "Name3" },
	{ 7, "Name1" },
	{ 8, "Name2" },
	{ 9, "Name3" }
};
*/


Dictionary<string, List<string>> toNameListDictionary = entity.ToNameListDictionary<string, string>();
/*
new Dictionary<string, List<string>> 
{ 
	{ "SCName1", new List<string> { "Name1", "Name2", "Name3" } },
	{ "SCName2", new List<string> { "Name1", "Name2", "Name3" } },
	{ "SCName3", new List<string> { "Name1", "Name2", "Name3" } } 
};
*/


Dictionary<string, List<int>> toValueListDictionary = entity.ToValueListDictionary<string, int>();
/*
new Dictionary<string, List<int>> 
{ 
	{ "SCName1", new List<int> { 1, 2, 3 } },
	{ "SCName2", new List<int> { 4, 5, 6 } },
	{ "SCName3", new List<int> { 7, 8, 9 } } 
};
*/


Dictionary<string, Dictionary<string, int>> toDictionaryDictionary = entity.ToDictionaryDictionary<string, string, int>();
/*
new Dictionary<string, Dictionary<string, int>> 
{ 
	{ 
		"SCName1", 
		new Dictionary<string, int> 
		{ 
			{ "Name1", 1 },
			{ "Name2", 2 },
			{ "Name3", 3 }
		} 
	},
	{ 
		"SCName2", 
		new Dictionary<string, int> 
		{ 
			{ "Name1", 4 },
			{ "Name2", 5 },
			{ "Name3", 6 }
		} 
	},
	{ 
		"SCName3", 
		new Dictionary<string, int> 
		{ 
			{ "Name1", 7 },
			{ "Name2", 8 },
			{ "Name3", 9 }
		} 
	} 
};
*/


Dictionary<string, Dictionary<int, string>> toValueKeyDictionaryDictionary = entity.ToValueKeyDictionaryDictionary<string, int, string>();
/*
new Dictionary<string, Dictionary<int, string>> 
{ 
	{ 
		"SCName1", 
		new Dictionary<int, string> 
		{ 
			{ 1, "Name1" },
			{ 2, "Name2" },
			{ 3, "Name3" }
		} 
	},
	{ 
		"SCName2", 
		new Dictionary<int, string> 
		{ 
			{ 4, "Name1" },
			{ 5, "Name2" },
			{ 6, "Name3" }
		} 
	},
	{ 
		"SCName3", 
		new Dictionary<int, string> 
		{ 
			{ 7, "Name1" },
			{ 8, "Name2" },
			{ 9, "Name3" }
		} 
	} 
};
*/

Last edited Dec 19, 2011 at 5:08 AM by kojiishi, version 2

Comments

No comments yet.